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);
     }

最新文章

  1. ASP.NET知识总结(2.对比Get和Post提交方式)
  2. Skype无法收发组消息
  3. vi编辑器的简单使用
  4. set -x与set +x指令
  5. java 打印出99乘法口诀表
  6. PLSQL_性能优化系列20_Oracle Result Cash结果缓存
  7. Chapter 6 Windows下编译pycaffe
  8. java读取xml(当xml放在包里时)
  9. Android开发之漫漫长途 Ⅱ——Activity的显示之Window和View(2)
  10. JPA(API)
  11. 错误:Java HotSpot(TM) 64-Bit Server VM warning: Insufficient space for shared memory file
  12. python问题:AttributeError: &#39;module&#39; object has no attribute &#39;SSL_ST_INIT&#39;
  13. 不利用C语言库函数,实现字符串相关函数
  14. mvc core2.1 Identity.EntityFramework Core 导航状态栏(六)
  15. grpc-golang实现账号and密码认证
  16. Redis 慢查询
  17. Beanstalkd 的理解
  18. 查看JSTL的doc解决问题
  19. 远程使用tomcat8的首页的管理工具
  20. 线程的sleep()方法和yield()方法区别

热门文章

  1. gRPC入坑记
  2. Excel导出打印失败报错 (eg HSSF instead of XSSF)
  3. Linux嵌入式kgdb调试环境搭建
  4. 使用 Mybatis 框架 jdbc 方式批量写入 SQL Server,报错 com.microsoft.sqlserver.jdbc.SQLServerException 传入的表格格式数据流(TDS)远程过程调用(RPC)协议流不正确。此 RPC 请求中提供了过多的参数,最多应为2100
  5. Oracle数据库---触发器
  6. Pandas Series 与 DataFrame 数据创建
  7. java 带静态域的导出类创建时都发生了什么?
  8. HDU - 1232 畅通工程【并查集】
  9. 基于SpringBoot+Redis的Session共享与单点登录
  10. 将个人网站主页设置为Tomcat默认打开页面