2 回答
TA贡献1824条经验 获得超8个赞
这是我最终使用的配置文件。我没有包含任何与日志记录相关的依赖项,也没有添加任何排除到 pdfbox 依赖项,只是将此文件添加到包含 application.properties 文件的文件夹中。
文件名是 logback-spring.xml
洪水记录器是从如何更改java中第3方库的日志级别复制的
<property name="LOGS" value="./logs" />
<appender name="Console"
class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable
</Pattern>
</layout>
</appender>
<appender name="RollingFile"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGS}/spring-boot-logger.log</file>
<encoder
class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
</encoder>
<rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily and when the file reaches 10 MegaBytes -->
<fileNamePattern>${LOGS}/archived/spring-boot-logger-%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<!-- LOG everything at INFO level -->
<root level="info">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</root>
<!-- LOG "com.baeldung*" at TRACE level -->
<logger name="org.apache" level="ERROR" additivity="false">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</logger>
<logger name="flooding logger" level="ERROR" additivity="false">
<appender-ref ref="Console"/>
TA贡献2039条经验 获得超7个赞
这是我在“旧”log4j 文件中使用的内容log4j.properties(您应该迁移到 log4j2):
log4j.logger.org.springframework=WARN
log4j.logger.org.apache.pdfbox.pdmodel.font.PDCIDFontType2=FATAL
在“新”中log4j2.xml我有这个(附加器被命名为STDOUT和A1):
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://logging.apache.org/log4j/2.x/manual/configuration.html
https://logging.apache.org/log4j/2.x/manual/appenders.html
-->
<Configuration>
<Appenders>
....
....
</Appenders>
<Loggers>
<Logger name="org.springframework" level="warn" additivity="false">
<AppenderRef ref="STDOUT"/>
<AppenderRef ref="A1"/>
</Logger>
<Logger name="org.apache.pdfbox.pdmodel.font.PDCIDFontType2" level="fatal" additivity="false">
<AppenderRef ref="STDOUT"/>
<AppenderRef ref="A1"/>
</Logger>
<Root level="info">
<AppenderRef ref="STDOUT"/>
<AppenderRef ref="A1"/>
</Root>
</Loggers>
</Configuration>
添加回答
举报