我需要在现有的Java / spring-boot项目中启用调试,信息日志。
这是原始的application.properties文件:
logging.level.org.springframework=WARN
logging.level.io.comp=INFO
这是原始的logback.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<property name="LOGS_PATH" value="./logs" />
<appender name="ERROR_LOG_FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<file>${LOGS_PATH}/${NODE_NAME}_error.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<charset>UTF-8</charset>
<Pattern>
%d{dd/MM/yyyy HH:mm:ss.SSS} [%thread][%-5level][%logger{0}] %msg%n
</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOGS_PATH}/archived/${NODE_NAME}_error.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>
<appender name="DEBUG_LOG_FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGS_PATH}/${NODE_NAME}_debug.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<charset>UTF-8</charset>
<Pattern>
%d{dd/MM/yyyy HH:mm:ss.SSS} [%thread][%-5level][%logger{0}] %msg%n
</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOGS_PATH}/archived/${NODE_NAME}_debug.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>
<appender name="INFO_LOG_FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>DEBUG</level>
<onMatch>DENY</onMatch>
</filter>
<file>${LOGS_PATH}/${NODE_NAME}.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<charset>UTF-8</charset>
<Pattern>
%d{dd/MM/yyyy HH:mm:ss.SSS} [%thread][%-5level][%logger{0}] %msg%n
</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOGS_PATH}/archived/${NODE_NAME}.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>
<appender name="DUMP_LOG_FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGS_PATH}/${NODE_NAME}_dump.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<charset>UTF-8</charset>
<Pattern>
%d{dd/MM/yyyy HH:mm:ss.SSS} [%thread][%-5level][%logger{0}] %msg%n
</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOGS_PATH}/archived/${NODE_NAME}_dump.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<maxHistory>10</maxHistory>
</rollingPolicy>
</appender>
<!-- Loggers -->
<logger name="io.comp" additivity="true">
<level value="DEBUG" />
<appender-ref ref="DEBUG_LOG_FILE" />
<appender-ref ref="ERROR_LOG_FILE" />
</logger>
<!-- Root Logger -->
<root level="DEBUG" >
<appender-ref ref="DUMP_LOG_FILE" />
<appender-ref ref="ERROR_LOG_FILE" />
</root>
<root level="INFO" >
<appender-ref ref="INFO_LOG_FILE" />
</root>
我试图将application.properties文件更改为:
logging.level.org.springframework=DEBUG
logging.level.io.comp=DEBUG
和logback.xml文件保存到:
<?xml version="1.0" encoding="UTF-8"?>
<property name="LOGS_PATH" value="./logs" />
<appender name="ERROR_LOG_FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
</filter>
<file>${LOGS_PATH}/${NODE_NAME}_error.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<charset>UTF-8</charset>
<Pattern>
%d{dd/MM/yyyy HH:mm:ss.SSS} [%thread][%-5level][%logger{0}] %msg%n
</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOGS_PATH}/archived/${NODE_NAME}_error.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>
<appender name="DEBUG_LOG_FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGS_PATH}/${NODE_NAME}_debug.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<charset>UTF-8</charset>
<Pattern>
%d{dd/MM/yyyy HH:mm:ss.SSS} [%thread][%-5level][%logger{0}] %msg%n
</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOGS_PATH}/archived/${NODE_NAME}_debug.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>
<appender name="INFO_LOG_FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
</filter>
<file>${LOGS_PATH}/${NODE_NAME}.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<charset>UTF-8</charset>
<Pattern>
%d{dd/MM/yyyy HH:mm:ss.SSS} [%thread][%-5level][%logger{0}] %msg%n
</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOGS_PATH}/archived/${NODE_NAME}.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>
<appender name="DUMP_LOG_FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGS_PATH}/${NODE_NAME}_dump.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<charset>UTF-8</charset>
<Pattern>
%d{dd/MM/yyyy HH:mm:ss.SSS} [%thread][%-5level][%logger{0}] %msg%n
</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOGS_PATH}/archived/${NODE_NAME}_dump.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<maxHistory>10</maxHistory>
</rollingPolicy>
</appender>
<!-- Loggers -->
<logger name="io.comp" additivity="true">
<level value="DEBUG" />
<appender-ref ref="DEBUG_LOG_FILE" />
<appender-ref ref="INFO_LOG_FILE" />
<appender-ref ref="ERROR_LOG_FILE" />
</logger>
<!-- Root Logger -->
<root level="DEBUG" >
<appender-ref ref="DUMP_LOG_FILE" />
<appender-ref ref="ERROR_LOG_FILE" />
<appender-ref ref="DEBUG_LOG_FILE" />
</root>
<root level="INFO" >
<appender-ref ref="INFO_LOG_FILE" />
<appender-ref ref="DEBUG_LOG_FILE" />
</root>
,但没有成功。仅将级别为:错误,警告(log.error,log.warn)的日志打印到文件中。
我在做什么错?
答案 0 :(得分:0)
我发现了问题
在项目的配置中,引用了另一个属性文件,其中Logger级别为WARN。