mem*_*und 16 java spring log4j log4j2 spring-boot
我正在使用spring-boot-starter,并希望配置log4j2.xml为将异步+不同的内容记录到不同的日志文件.
我创建了log4j2文件,但Spring仍然使用spring-boot默认日志记录.如何切换日志记录?
kle*_*eko 44
我有一个更好的方法:
排除logback记录器:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
Run Code Online (Sandbox Code Playgroud)添加log4j2启动启动器:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)来源:http://docs.spring.io/spring-boot/docs/1.5.1.RELEASE/reference/htmlsingle/#howto-configure-log4j-for-logging
请享用!
小智 9
试试这个:
排除spring-boot-starter-logging例如
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
Run Code Online (Sandbox Code Playgroud)为日志记录界面添加依赖项,例如slf4j
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.0.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)添加指向所选日志记录接口的其他日志记录实
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)添加目标日志记录实现,例如
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)它应该工作.
| 归档时间: |
|
| 查看次数: |
21103 次 |
| 最近记录: |