spring boot 加载自定义log4j 文件路径
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);
}
spring boot 加载自定义log4j 文件路径的更多相关文章
- spring boot加载自定义配置
1.通过@Value 配置文件中 wechat: ssh: host: 192.0.1.1 port: 22 加载类 @Component @Data public class SftpConfig ...
- Spring Boot加载配置文件
问题1:Spring如何加载配置,配置文件位置? 1.默认位置: Spring Boot默认的配置文件名称为application.properties,SpringApplication将从以下位置 ...
- Spring Boot加载application.properties配置文件顺序规则
SpringApplication会从以下路径加载所有的application.properties文件: 1.file:./config/(当前目录下的config文件夹) 2.file:./(当前 ...
- spring boot 加载web容器tomcat流程源码分析
spring boot 加载web容器tomcat流程源码分析 我本地的springboot版本是2.5.1,后面的分析都是基于这个版本 <parent> <groupId>o ...
- Spring中加载ApplicationContext.xml文件的方式
Spring中加载ApplicationContext.xml文件的方式 原文:http://blog.csdn.net/snowjlz/article/details/8158560 1.利用Cla ...
- spring boot 加载配置 文件
在springboot启动的过程中,默契情况下会在classpath路径下加载application.properties当做系统配置文件,但有时候我们想要替换成另一个文件,可以 通过以下方式: ...
- dojo 加载自定义module的路径问题
因为最近想学学ArcGIS API for JavaScript ,翻了下ESRI的官网guide,发现其是基于dojo框架的,看了两页实在看不懂,于是先来熟悉下dojo框架.人蠢不能怪社会%> ...
- Spring boot加载REACTIVE源码分析
一,加载REACTIVE相关自动配置 spring boot通过判断含org.springframework.web.reactive.DispatcherHandler字节文件就确定程序类型是REA ...
- laravel 自动加载 自定义的文件/辅助函数
需求 在 laravel 中自定义了一些 辅助函数,想要laravel框架自动加载这些函数 实现 将自定义的辅助函数放在helpers.php文件中,如下: 在compsoer.json 的 auto ...
随机推荐
- 通过CDN引入jQuery的几种方式
百度 CDN <head> <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" ...
- InnoDB存储引擎--学习笔记-redo log
目录 1. 引言 2. 重做日志文件和相关概念介绍 + 2.1. 重做日志文件和bin log + 2.2. LSN(log squence number) 3. 重做日志文件基本工作原理 4. 重做 ...
- scrapy实战6爬取IT桔子国内所有融资公司:
爬取融资公司,融资公司简介,融资时间,轮次,融资额,投资方,股权占比以及融资公司完整融资历史 如图 源码地址:https://github.com/huwei86/spiderITjuzi
- SQL Server Form子查询、链接查询
所用数据表:用户,钱包,订单 一.from子查询 --查询钱包里金额大于30000 and User_ID = Users.ID) ) 二.链接查询 内连接(inner join)外连接(left/r ...
- crontab 中curl命令无法正常执行
这里所指curl无法执行Url情况是针对带参数的链接,方法体中无法获取参数的值. 比如: */7 * * * * curl http://localhost:8088/backening/sysOrd ...
- 剑指offer第二版-5.替换空格
面试题5:替换空格 题目要求: 实现一个函数,把字符串中的每个空格都替换成“%20”,已知原位置后面有足够的空余位置,要求改替换过程发生在原来的位置上. 思路: 首先遍历字符串求出串中空格的数量,求出 ...
- J2EE:Servlet上传文件到服务器,并相应显示
Servlet 可以与HTML一起使用来允许用户上传文件到服务器 编辑上传文件的页面upload.html 注意事项:上传方式使用POST不能使用GET(GET不能上传文件) 表单 enctype 属 ...
- 使用flink Table &Sql api来构建批量和流式应用(3)Flink Sql 使用
从flink的官方文档,我们知道flink的编程模型分为四层,sql层是最高层的api,Table api是中间层,DataStream/DataSet Api 是核心,stateful Stream ...
- UVA12657 Boxes in a Line:题解
题目链接:https://www.luogu.org/problemnew/show/UVA12657 分析: 此题使用手写链表+模拟即可.(其实可以用list,而且更简便,但是会大大的超时) 肯定是 ...
- Excel催化剂开源第27波-Excel离线生成词云图
在数据分析领域,词云图已经成为在文本分析中装逼的首选图表,大家热烈地讨论如何在Python上做数据分析.做词云图. 数据分析从来都是Excel的主战场,能够让普通用户使用上的技术才是最有价值的技术,一 ...