java spring boot 写入日志
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"; } }
显示控制台
日志文件
如果遇到什么不懂的地方直接关注公众号留言(本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。)
作者:newmiracle
出处:https://www.cnblogs.com/newmiracle/