[logback-user] Logback Rolling policy issue.
Troy Hart
troy.hart at gmail.com
Wed Mar 12 19:03:07 CET 2014
Below is an example of some configuration that I use to do the same thing.
I hate that there is a requirement in my organization to do this however,
it's the wrong way about it if you ask me. For my money, I think you need
to strive for log centralization and this represents an effort to
decentralize logs. There are a set of tools that I'd recommend using for
log centralization. Namely, Logstash backed by Elasticsearch and Kibana.
I'd urge you to look at how these tools can help you.
<?xml version="1.0" encoding="UTF-8"?>
> <configuration debug="true">
> <contextListener
> class="ch.qos.logback.classic.jul.LevelChangePropagator">
> <resetJUL>true</resetJUL>
> </contextListener>
> <property name="contextName" value="someapp" />
> <contextName>${contextName}</contextName>
> <jmxConfigurator />
> <appender name="default"
> class="ch.qos.logback.core.rolling.RollingFileAppender">
> <append>true</append>
> <file>${logging.log_dir}/${contextName}.log</file>
> <rollingPolicy
> class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
> <cleanHistoryOnStart>true</cleanHistoryOnStart>
> <maxHistory>${logging.appender_max_file_history:-1}</maxHistory>
>
> <fileNamePattern>${logging.log_archive_dir}/${contextName}.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
> <timeBasedFileNamingAndTriggeringPolicy
> class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
> <maxFileSize>${logging.appender_max_file_size}</maxFileSize>
> </timeBasedFileNamingAndTriggeringPolicy>
> </rollingPolicy>
> <encoder class="${logging.encoder.default}" />
> </appender>
> <appender name="error"
> class="ch.qos.logback.core.rolling.RollingFileAppender">
> <append>true</append>
> <filter class="ch.qos.logback.classic.filter.LevelFilter">
> <level>ERROR</level>
> <onMatch>ACCEPT</onMatch>
> <onMismatch>DENY</onMismatch>
> </filter>
> <file>${logging.log_dir}/${contextName}-errors.log</file>
> <rollingPolicy
> class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
> <cleanHistoryOnStart>true</cleanHistoryOnStart>
> <maxHistory>${logging.appender_max_file_history:-1}</maxHistory>
>
> <fileNamePattern>${logging.log_archive_dir}/${contextName}-errors.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
> <timeBasedFileNamingAndTriggeringPolicy
> class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
> <maxFileSize>${logging.appender_max_file_size}</maxFileSize>
> </timeBasedFileNamingAndTriggeringPolicy>
> </rollingPolicy>
> <encoder class="${logging.encoder.default}" />
> </appender>
> <root level="${logging.level.default}">
> <appender-ref ref="default"/>
> <appender-ref ref="error"/>
> </root>
> </configuration>
On Wed, Mar 12, 2014 at 11:51 AM, Chandraprakash <
chandraprakash.kalwar at gmail.com> wrote:
> Dear Troy,
>
> Thanks a lot to help with the appender configurations. I applied the
> similar
> configurations and it is working for me now :-)
>
> Now I am trying to get all the 'info' and 'error' level logs in one
> file(infoLogAppender) and all the 'error' level logs in a sepaate
> log(errorLogAppender) as well. I tried it using 'LevelFilter' and using
> 'logger' as well, but it did not work. My configurations looks like:
>
> <property name="logging.log_dir" value="C:/Logs"/>
> <property name="logging.log_archive_dir" value="C:/Logs/Archive"/>
> <property name="infoLogName" value="someInfoLog"/>
> <property name="errorLogName" value="someErrorLog"/>
> <property name="consoleLogName" value="consoleLog"/>
>
>
> <appender name="infoLogAppender"
> class="ch.qos.logback.core.rolling.RollingFileAppender">
> <append>true</append>
> <file>${logging.log_dir}/${infoLogName}.log</file>
> <rollingPolicy
> class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
> <maxHistory>10</maxHistory>
>
>
> <fileNamePattern>${logging.log_archive_dir}/${infoLogName}.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
> <timeBasedFileNamingAndTriggeringPolicy
> class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
> <maxFileSize>10KB</maxFileSize>
> </timeBasedFileNamingAndTriggeringPolicy>
> </rollingPolicy>
> <encoder>
>
> <pattern>%-30(%d{HH:mm:ss.SSS} [%thread]) %-5level
> %-20.50logger{35}
> - %msg%n</pattern>
>
> <immediateFlush>false</immediateFlush>
> </encoder>
> </appender>
>
> <appender name="errorLogAppender"
> class="ch.qos.logback.core.rolling.RollingFileAppender">
> <append>true</append>
> <file>${logging.log_dir}/${errorLogName}.log</file>
> <rollingPolicy
> class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
> <maxHistory>10</maxHistory>
>
>
> <fileNamePattern>${logging.log_archive_dir}/${errorLogName}.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
> <timeBasedFileNamingAndTriggeringPolicy
> class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
> <maxFileSize>1MB</maxFileSize>
> </timeBasedFileNamingAndTriggeringPolicy>
> </rollingPolicy>
> <encoder>
>
> <pattern>%-30(%d{HH:mm:ss.SSS} [%thread]) %-5level
> %-20.50logger{35}
> - %msg%n</pattern>
>
> <immediateFlush>true</immediateFlush>
> </encoder>
> </appender>
>
> <appender name="consoleAppender"
> class="ch.qos.logback.core.ConsoleAppender">
> <append>true</append>
> <file>${logging.log_dir}/${consoleLogName}.log</file>
> <rollingPolicy
> class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
> <maxHistory>10</maxHistory>
>
>
> <fileNamePattern>${logging.log_archive_dir}/${consoleLogName}.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
> <timeBasedFileNamingAndTriggeringPolicy
> class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
> <maxFileSize>1MB</maxFileSize>
> </timeBasedFileNamingAndTriggeringPolicy>
> </rollingPolicy>
> <encoder>
>
> <pattern>%-30(%d{HH:mm:ss.SSS} [%thread]) %-5level
> %-20.50logger{35}
> - %msg%n</pattern>
>
> <immediateFlush>true</immediateFlush>
> </encoder>
> </appender>
>
> <root level="TRACE" additivity="true">
> <appender-ref ref="infoLogAppender" />
> <appender-ref ref="errorLogAppender" />
> <appender-ref ref="consoleAppender" />
> </root>
>
>
> I get some logs on console as well(mainly JPA related). I want them in a
> separate log file(consoleAppender). It is also not working.
>
> Could you help here as well? Might be with some example?
>
> Regards,
> Chandra
>
>
>
> --
> View this message in context:
> http://logback.10977.n7.nabble.com/Logback-Rolling-policy-issue-tp13350p13383.html
> Sent from the Users mailing list archive at Nabble.com.
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://mailman.qos.ch/mailman/listinfo/logback-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20140312/7f82f01a/attachment.html>
More information about the Logback-user
mailing list