java - How to keep rolling log file as per file size? -
i working on project in logging bunch of stuff in file , want make sure log file getting rolled fixed limit file reached. have below logback.xml
file looks file size not working. see file size 793m limit have 100m
<configuration> <appender name="file" class="ch.qos.logback.core.fileappender"> <file>process.log</file> <triggeringpolicy class="ch.qos.logback.core.rolling.sizebasedtriggeringpolicy"> <maxfilesize>100mb</maxfilesize> </triggeringpolicy> <rollingpolicy class="ch.qos.logback.core.rolling.fixedwindowrollingpolicy"> <filenamepattern>process%i.log</filenamepattern> <minindex>1</minindex> <maxindex>9</maxindex> </rollingpolicy> <encoder> <pattern>%date %level [%thread] %msg%n</pattern> <!-- improves logging throughput --> <immediateflush>true</immediateflush> </encoder> </appender> <appender name="stdout" class="ch.qos.logback.core.consoleappender"> <!-- encoders assigned type ch.qos.logback.classic.encoder.patternlayoutencoder default --> <encoder> <pattern>%d{hh:mm:ss.sss} [%thread] %-5level %logger{36} - %msg%n </pattern> </encoder> </appender> <root level="info"> <appender-ref ref="file" /> <appender-ref ref="stdout" /> </root> </configuration>
what wrong doing here? , best policy should follow in production in terms of logging? logging bunch of stuff in file , don't want fill disk log file.
instead of fileappender, should using rollingfileappender. see: http://logback.qos.ch/manual/appenders.html
you specifying settings/properties intended used rollingfileappender , ignored fileappender.
for example usage , configuration, refer link: http://examples.javacodegeeks.com/enterprise-java/logback/logback-rollingfileappender-example/
sample logback.xml using rollingfileappender , consoleappender. rollingfileappender both size , time based:
<?xml version="1.0" encoding="utf-8"?> <configuration scan="true"> <appender name="consoleappender" class="ch.qos.logback.core.consoleappender"> <encoder> <charset>utf-8</charset> <pattern>%d %-4relative [%thread] %-5level %logger{35} - %msg%n</pattern> </encoder> </appender> <appender name="file" class="ch.qos.logback.core.rolling.rollingfileappender"> <file>/srv/logs/application.log</file> <rollingpolicy class="ch.qos.logback.core.rolling.timebasedrollingpolicy"> <filenamepattern>logfile.%d{yyyy-mm-dd}.log</filenamepattern> <maxhistory>30</maxhistory> </rollingpolicy> <triggeringpolicy class="ch.qos.logback.core.rolling.sizebasedtriggeringpolicy"> <maxfilesize>5mb</maxfilesize> </triggeringpolicy> <encoder> <charset>utf-8</charset> <pattern>%d %-4relative [%thread] %-5level %logger{35} - %msg%n</pattern> </encoder> </appender> <root level="debug"> <appender-ref ref="consoleappender" /> <appender-ref ref="file"/> </root> </configuration>
Comments
Post a Comment