多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## 概述 Log4j是一种非常流行的日志框架,最新版本是2.x。 <br /> ## 安装 依赖 > pom.xml ```xml <!-- log4j日志组件 --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.17.1</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-to-slf4j</artifactId> <version>2.17.1</version> </dependency> ``` 输出日志级别配置 > application.yaml ```yml # 日志配置 logging: level: com.edk24: debug org.springframework: warn ``` `com.edk24` 换成你的包名 ## 单独实例化使用 ```java import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class BaseController { protected final Logger logger = LoggerFactory.getLogger(this.getClass()); } ``` ## 完成效果 ```bash 2023-02-06T15:50:19.716+08:00 INFO 43250 --- [nio-8081-exec-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 2023-02-06T15:50:19.922+08:00 INFO 43250 --- [nio-8081-exec-1] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl@76cbac33 2023-02-06T15:50:19.923+08:00 INFO 43250 --- [nio-8081-exec-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. 2023-02-06T15:50:19.927+08:00 DEBUG 43250 --- [nio-8081-exec-1] c.e.b.mapper.SysUserMapper.list_COUNT : ==> Preparing: SELECT count(0) FROM sys_user 2023-02-06T15:50:19.938+08:00 DEBUG 43250 --- [nio-8081-exec-1] c.e.b.mapper.SysUserMapper.list_COUNT : ==> Parameters: 2023-02-06T15:50:19.951+08:00 DEBUG 43250 --- [nio-8081-exec-1] c.e.b.mapper.SysUserMapper.list_COUNT : <== Total: 1 2023-02-06T15:50:19.954+08:00 DEBUG 43250 --- [nio-8081-exec-1] c.edk24.blog.mapper.SysUserMapper.list : ==> Preparing: select id, nickname, username from sys_user limit ?,? 2023-02-06T15:50:19.954+08:00 DEBUG 43250 --- [nio-8081-exec-1] c.edk24.blog.mapper.SysUserMapper.list : ==> Parameters: 0(Integer), 1(Integer) 2023-02-06T15:50:19.957+08:00 DEBUG 43250 --- [nio-8081-exec-1] c.edk24.blog.mapper.SysUserMapper.list : <== Total: 1 ```