pom.xml
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </dependency>
application.yaml配置
logging: level: root: INFO file: name: log/sys.log # 根目录下创建log目录,保存为sys.log文件 logback: rollingpolicy: # gz file-name-pattern: ${LOG_FILE}.%d{yyyy-MM-dd}.%i.zip max-file-size: 1MB pattern: dateformat: yyyy-MM-dd HH:mm:ss
示例
package com.xcg.webapp.Controller; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/Test") public class TestController { private static final Logger logger = LoggerFactory.getLogger(TestController.class); @GetMapping("/writeLog") public String writeLog() { logger.info("this is a test message!"); System.out.println(logger.getClass().toString()); //class ch.qos.logback.classic.Logger return "welcome to spring boot3"; } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· Vue3状态管理终极指南:Pinia保姆级教程
2020-04-23 jquery操作checkbox
2019-04-23 WPF打印京东电子面单(可以异步)
2018-04-23 Http方式下载文件