В моем Java-приложении я использую maven и springboot, log4j
для ведения журнала.Проблема в регистрации.log4j
больше не имеет управления журналом после запуска springboot(SpringApplication.run(Starter.class);)
.Пожалуйста, смотрите main()
ниже.После запуска springboot
он подчиняется logging.level.*.
в файле свойств.Не уверен, что я делаю не так.
public static void main(String[] args) {
logger.info("started"); //It logs this with log4j
SpringApplication.run(Starter.class);
logger.info("started");//but it does not log this.
}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Properties>
<Property name="logPath">${sys:user.home}</Property>
<Property name="logPattern">[%-5level] %d{HH:mm:ss.SSS} %logger{36}.[ %C{5} , %M , %F,%L ] - %msg%n</Property>
</Properties>
<Appenders>
<RollingRandomAccessFile name="prodLog" fileName="${logPath}/log.log"
filePattern="${logPath}/log/%d{yyyy-MM-dd}-%i.log.zip">
<PatternLayout
pattern="${logPattern}"/>
<Policies>
<TimeBasedTriggeringPolicy interval="24" modulate="true"/>
<SizeBasedTriggeringPolicy size="10 MB"/>
</Policies>
<DefaultRolloverStrategy max="5"/>
</RollingRandomAccessFile>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout
pattern="${logPattern}"/>
</Console>
</Appenders>
<Loggers>
<AsyncRoot level="DEBUG" includeLocation="true">
<AppenderRef ref="STDOUT"/>
<AppenderRef ref="prodLog"/>
</AsyncRoot>
</Loggers>
<?xml version="1.0" encoding="UTF-8"?>
<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.testApp.test</groupId>
<artifactId>testApp</artifactId>
<version>1.1.2-SNAPSHOT</version>
<properties/>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>10</source>
<target>10</target>
<release>10</release>
<compilerArgs>
<arg>-Xlint:all,-processing</arg>
</compilerArgs>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
</dependencies>
</project>