spring boot 加载自定义log4j 文件路径
2024-09-01 18:14:52
spring boot 使用log4j 打印时,需首先去除自带 Logger ,然后加入log4j 依赖
<dependencies> <!-- https://mvnrepository.com/artifact/junit/junit --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-log4j --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j</artifactId> <version>1.3.8.RELEASE</version> </dependency>
然后加载自定义 log4j 配置文件,比如我们把 log4j 文件放到 resources/config/log4j/log4j.xml 下,
在启动 spring 之前,加载 log4j 文件
/** * 初始化 log4j */ public static void loadLog4j() { DOMConfigurator configurator = new DOMConfigurator(); ClassLoader classLoader = Application.class.getClassLoader(); URL url = classLoader.getResource(GlobalConstant.FilePath.log4j_file); configurator.doConfigure(url, LogManager.getLoggerRepository()); } public static void main(String[] args) throws Exception { //加载 log4j文件 loadLog4j(); SpringApplication.run(Application.class, args); }
最新文章
- ASP.NET知识总结(2.对比Get和Post提交方式)
- Skype无法收发组消息
- vi编辑器的简单使用
- set -x与set +x指令
- java 打印出99乘法口诀表
- PLSQL_性能优化系列20_Oracle Result Cash结果缓存
- Chapter 6 Windows下编译pycaffe
- java读取xml(当xml放在包里时)
- Android开发之漫漫长途 Ⅱ——Activity的显示之Window和View(2)
- JPA(API)
- 错误:Java HotSpot(TM) 64-Bit Server VM warning: Insufficient space for shared memory file
- python问题:AttributeError: &#39;module&#39; object has no attribute &#39;SSL_ST_INIT&#39;
- 不利用C语言库函数,实现字符串相关函数
- mvc core2.1 Identity.EntityFramework Core 导航状态栏(六)
- grpc-golang实现账号and密码认证
- Redis 慢查询
- Beanstalkd 的理解
- 查看JSTL的doc解决问题
- 远程使用tomcat8的首页的管理工具
- 线程的sleep()方法和yield()方法区别
热门文章
- gRPC入坑记
- Excel导出打印失败报错 (eg HSSF instead of XSSF)
- Linux嵌入式kgdb调试环境搭建
- 使用 Mybatis 框架 jdbc 方式批量写入 SQL Server,报错 com.microsoft.sqlserver.jdbc.SQLServerException 传入的表格格式数据流(TDS)远程过程调用(RPC)协议流不正确。此 RPC 请求中提供了过多的参数,最多应为2100
- Oracle数据库---触发器
- Pandas Series 与 DataFrame 数据创建
- java 带静态域的导出类创建时都发生了什么?
- HDU - 1232 畅通工程【并查集】
- 基于SpringBoot+Redis的Session共享与单点登录
- 将个人网站主页设置为Tomcat默认打开页面