Details
-
Bug
-
Resolution: Unresolved
-
Major
-
None
-
1.2.3
-
None
-
package test;
import java.io.File;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;public final class Test {
public final static Logger log = LoggerFactory.getLogger(Test.class);
public static void main(String[] args) throws Exception {
log.error("ZZZZZZZZZZZZZZZZZZZZZZZZZ");
ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
LoggerContext lc = (LoggerContext) loggerFactory;
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(lc);
lc.reset();final File file = new File("./config/logback.xml");
lc.putProperty("application-name", "applicationName");
configurator.doConfigure(file.getAbsolutePath());
while (true) {
log.info("YY");
Thread.sleep(5000);
System.err.println("X");}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="true" nolog="true" scanPeriod="60 seconds"><property name="logging_home" value="logs/${application-name}" />
<property name="logging_backup_home" value="${logging_home}/backup" /><appender name="fileInfoLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logging_home}/logging-info.log</file>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>DENY</onMatch>
<onMismatch>ACCEPT</onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<FileNamePattern>
${logging_backup_home}/%d{yyyy-MM-dd}/logging-info.%d{yyyyMMdd}.%i.log.zip
</FileNamePattern>
<maxHistory>30</maxHistory>
<maxFileSize>128MB</maxFileSize>
</rollingPolicy><layout class="ch.qos.logback.classic.PatternLayout">
<pattern>
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%-5level] [%logger:%line] - %msg%n
</pattern>
</layout>
</appender><root level="DEBUG">
<appender-ref ref="fileInfoLog" />
</root></configuration>
package test; import java.io.File; import org.slf4j.ILoggerFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.joran.JoranConfigurator; public final class Test { public final static Logger log = LoggerFactory.getLogger(Test.class); public static void main(String[] args) throws Exception { log.error("ZZZZZZZZZZZZZZZZZZZZZZZZZ"); ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory(); LoggerContext lc = (LoggerContext) loggerFactory; JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(lc); lc.reset(); final File file = new File("./config/logback.xml"); lc.putProperty( "application-name" , "applicationName"); configurator.doConfigure(file.getAbsolutePath()); while (true) { log.info("YY"); Thread.sleep(5000); System.err.println("X"); } } } <?xml version="1.0" encoding="UTF-8"?> <configuration debug="false" scan="true" nolog="true" scanPeriod="60 seconds"> <property name="logging_home" value="logs/ ${application-name} " /> <property name="logging_backup_home" value="${logging_home}/backup" /> <appender name="fileInfoLog" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${logging_home}/logging-info.log</file> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>ERROR</level> <onMatch>DENY</onMatch> <onMismatch>ACCEPT</onMismatch> </filter> <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <FileNamePattern> ${logging_backup_home}/%d{yyyy-MM-dd}/logging-info.%d{yyyyMMdd}.%i.log.zip </FileNamePattern> <maxHistory>30</maxHistory> <maxFileSize>128MB</maxFileSize> </rollingPolicy> <layout class="ch.qos.logback.classic.PatternLayout"> <pattern> %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%-5level] [%logger:%line] - %msg%n </pattern> </layout> </appender> <root level="DEBUG"> <appender-ref ref="fileInfoLog" /> </root> </configuration>
Description
The application starts the specified name or process name, ouput loggings to directory->applicationName,then adjusts the logback.xml level="DEBUG" to level="INFO" during the running process, the application name policy implementation is invalid, the loggings output change to directory->application-name_IS_UNDEFINED.