日志未写入日志文件:Spring boot 和 log4j.properties
我的 log4j.properties
status=error
name=PropertiesConfig
filters=threshold
filter.threshold.type=ThresholdFilter
filter.threshold.level=debug
appenders=console,rolling
appender.console.type=Console
appender.console.name=STDOUT
appender.console.layout.type=PatternLayout
appender.console.layout.pattern=%d{yyyy-MM-dd'T'HH:mm:ss.SSS}{GMT+0}|%-5p|%c{1}|%M|%L|%replace{%m}{\r}{ }%n
# Rotate log file
appender.rolling.type=RollingFile
appender.rolling.name=LogToRollingFile
appender.rolling.fileName=/var/logs/app.log
appender.rolling.filePattern=/var/logs/backup/app-%d{MM-dd-yyyy}-%i.log
appender.rolling.layout.type=PatternLayout
appender.rolling.layout.pattern=%d{yyyy-MM-dd'T'HH:mm:ss.SSS}{GMT+0}|%-5p|%c{1}|%M|%L|%replace{%m}{\r}{ }%n
appender.rolling.policies.type=Policies
appender.rolling.policies.time.type=TimeBasedTriggeringPolicy
appender.rolling.policies.size.type=SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=100MB
appender.rolling.strategy.type=DefaultRolloverStrategy
appender.rolling.strategy.max=5
#loggers = rolling
rootLogger.level=info
rootLogger.appenderRefs=stdout
rootLogger.appenderRef.stdout.ref=STDOUT
#logger.appenderRefs=rolling
rootLogger.appenderRef.rolling.ref=LogToRollingFile
依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</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-starter-log4j2</artifactId>
</dependency>
Log4 文件正在被选取,我可以看到日志以所需的格式打印,但文件附加器无法正常工作。
我错过了什么?
my log4j.properties
status=error
name=PropertiesConfig
filters=threshold
filter.threshold.type=ThresholdFilter
filter.threshold.level=debug
appenders=console,rolling
appender.console.type=Console
appender.console.name=STDOUT
appender.console.layout.type=PatternLayout
appender.console.layout.pattern=%d{yyyy-MM-dd'T'HH:mm:ss.SSS}{GMT+0}|%-5p|%c{1}|%M|%L|%replace{%m}{\r}{ }%n
# Rotate log file
appender.rolling.type=RollingFile
appender.rolling.name=LogToRollingFile
appender.rolling.fileName=/var/logs/app.log
appender.rolling.filePattern=/var/logs/backup/app-%d{MM-dd-yyyy}-%i.log
appender.rolling.layout.type=PatternLayout
appender.rolling.layout.pattern=%d{yyyy-MM-dd'T'HH:mm:ss.SSS}{GMT+0}|%-5p|%c{1}|%M|%L|%replace{%m}{\r}{ }%n
appender.rolling.policies.type=Policies
appender.rolling.policies.time.type=TimeBasedTriggeringPolicy
appender.rolling.policies.size.type=SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=100MB
appender.rolling.strategy.type=DefaultRolloverStrategy
appender.rolling.strategy.max=5
#loggers = rolling
rootLogger.level=info
rootLogger.appenderRefs=stdout
rootLogger.appenderRef.stdout.ref=STDOUT
#logger.appenderRefs=rolling
rootLogger.appenderRef.rolling.ref=LogToRollingFile
Dependecies :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</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-starter-log4j2</artifactId>
</dependency>
Log4 file is getting picked and i can see logs getting printed in the desired format, but file appender is not working .
what is being missed by me ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论