java spring boot 写入日志
1 配置文件
logging.file=myLog.log
logging.level.root=INFO
2 代码
package com.example.demo2122; import org.springframework.amqp.core.AmqpTemplate; import org.springframework.amqp.rabbit.annotation.RabbitHandler; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.slf4j.*; @RestController public class HelloControl { Logger logger = LoggerFactory.getLogger(getClass()); @GetMapping("/hello") public String hello(@RequestParam(value = "name", defaultValue = "World") String name) { logger.error("这是 error"); return "success"; } }
显示控制台
日志文件
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/18952.html