我正在尝试使用logback将spring-boot应用程序部署到现有的WildFly 8容器,但是一旦部署了应用程序,所有容器日志就会停止写入server.log
并最终被捕获应用程序日志。
症状类似于WildFly not logging after deploying app with Logback中描述的症状。如果我部署一个手动包含logback / slf4j依赖项的应用程序,那么应用程序就像我期望的那样(应用程序日志转到应用程序日志文件,容器日志转到server.log),所以我假设它与spring有关 - 开机?我可以配置这样,以便Wildfly继续处理容器记录吗?
的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.logging</groupId>
<artifactId>logger-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="path_base" value="d:/test-logger/" />
<property name="pattern"
value="%date{ISO8601} %level %class{30} %thread %msg %mdc %ex{full} %n" />
<!-- Simple File Appender -->
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${path_base}test-logger.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${path_base}/archive/%d{yyyy-MM,aux}/test-logger.log.%d.%i.gz
</fileNamePattern>
<maxHistory>90</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%date{ISO8601} %level %class{30} %thread %msg %mdc %ex{full} %n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="file" />
</root>
</configuration>
的JBoss-deployment.xml中
<jboss-deployment-structure>
<deployment>
<exclude-subsystems>
<subsystem name="logging" />
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
Spring启动初始化程序
package com.test;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
@SpringBootApplication
public class BootApp extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(
SpringApplicationBuilder builder) {
return builder.sources(BootApp.class);
}
}
答案 0 :(得分:1)
当我将spring-boot应用程序部署到websphere时,我遇到了类似的问题。应用程序打印完横幅后,来自websphere的所有日志消息都会记录到应用程序日志中。
问题出现了,因为spring-boot添加了 jul-to-slf4j.jar 之类的依赖项。这个jar实现类java.util.logging。*和websphere也使用java.util.logging因此从spring spring中排除jul-to-slf4j.jar我能够将所有websphere消息定向到容器日志,应用程序日志是写入应用程序日志。
答案 1 :(得分:0)
我遇到了类似的问题: 在Wildfly 9.0.2Final上运行Spring-boot 1.5.8
在容器处理日志记录之前,我必须排除以下内容:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
spring-boot-starter-data-jpa
有spring-boot-starter-logging
,其中包含我排除的依赖项。