Spring Boot Logback滚动文件追加程序不起作用 [英] spring boot logback rolling file append-er not working
问题描述
我正在开发一个spring boot应用程序,在这里我从Consul中的YML文件中读取logback配置.以下是我在YML文件中使用的配置.
I am developing a spring boot application, where I am reading the logback configuration from a YML file which is in Consul . Following are the configuration I have used in the YML file.
logging:
file: ./logs/application.log
pattern:
console: "%d %-5level %logger : %msg%n"
file: "%d %-4relative [%thread] %-5level %logger{35} - %msg%n"
level:
org.springframework.web: ERROR
com.myapp.somepackage: DEBUG
appenders:
logFormat: "%d %-4relative [%thread] %-5level %logger{35} - %msg%n"
currentLogFilename: ./logs/application.log
archivedLogFilenamePattern: ./logs/application-%d{yyyy-MM-dd}-%i.log.gz
archivedFileCount: 7
timeZone: UTC
maxFileSize: 30KB
maxHistory: 30
现在已经生成了日志文件,但是滚动追加程序不起作用,对此没有任何帮助,我正在寻找类似的东西,当我们从logback.xml文件执行滚动追加程序时,如下所示
Now the log files are generated, but the rolling appender is not working, any help on this, I am seraching for something similar like following when we perform rolling appender froma logback.xml file
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover. Make sure the path matches the one in the file element or else
the rollover logs are placed in the working directory. -->
<fileNamePattern>./logs/myapp/application_%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>5MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- keep 30 days' worth of history -->
<maxHistory>30</maxHistory>
</rollingPolicy>
我需要从YML文件进行配置
The same I need to configure from a YML file
推荐答案
经过大量搜索后,发现在Spring Boot中尚不支持此功能.这些选项仅是:
After a lot of search what I found is, this is not yet supported in spring boot. The options are only :
# LOGGING
logging.config= # Location of the logging configuration file. For instance `classpath:logback.xml` for Logback
logging.exception-conversion-word=%wEx # Conversion word used when logging exceptions.
logging.file= # Log file name. For instance `myapp.log`
logging.level.*= # Log levels severity mapping. For instance `logging.level.org.springframework=DEBUG`
logging.path= # Location of the log file. For instance `/var/log`
logging.pattern.console= # Appender pattern for output to the console. Only supported with the default logback setup.
logging.pattern.file= # Appender pattern for output to the file. Only supported with the default logback setup.
logging.pattern.level= # Appender pattern for log level (default %5p). Only supported with the default logback setup.
logging.register-shutdown-hook=false # Register a shutdown hook for the logging system when it is initialized.
所以,暂时不要在此上浪费时间.它将在20MB之后滚动,但是文件名类似于$ {your_file_name} .log.1等.Spring应该支持将滚动文件名模式提供给我们.而且它也不是存档文件.
So , dont waste your time on this for now. It will roll after 20MB , but the file name is like ${your_file_name}.log.1 etc. Spring should give support to give the rolling filename pattern to us. And also it is not an archived file.
这篇关于Spring Boot Logback滚动文件追加程序不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!