Logback rolling logging not working - java

I am trying to create logger policy in a spring based project.
The issue I am facing is related to rolling policy. the logfile.log is created and is working fine but the rolling file rollingfile.log.%d{yyyy-MM-dd}.log is not created.
Given below is my logback.xml.
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true" scan="true" scanPeriod="30 seconds">
<property name="LOG_PATH" value="D:/coinLogs" />
<property name="LOG_ARCHIVE" value="${LOG_PATH}/archive" />
<appender name="Console-Appender" class="ch.qos.logback.core.ConsoleAppender">
<layout>
<pattern>[%d{yyyy-MM-dd HH:mm:ss}] - [%X{requestId}] - %p %c -- %m%n</pattern>
</layout>
</appender>
<appender name="File-Appender" class="ch.qos.logback.core.FileAppender">
<file>${LOG_PATH}/logfile.log</file>
<encoder>
<pattern>[%d{yyyy-MM-dd HH:mm:ss}] - [%X{requestId}] - %p %c -- %m%n
</pattern>
<outputPatternAsHeader>true</outputPatternAsHeader>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${LOG_ARCHIVE}/rollingfile.log.%d{yyyy-MM-dd}.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<logger name="coinPay.logbackxml" level="info" additivity="false">
<appender-ref ref="Console-Appender" />
<appender-ref ref="File-Appender" />
</logger>
<!-- To remove extra hibernate logs -->
<logger name="org.hibernate">
<level value="info" />
</logger>
<root>
<appender-ref ref="Console-Appender" />
<appender-ref ref="File-Appender" />
</root>
</configuration>
any help will be appreciated. Thank you in advance :D

You need to specify ch.qos.logback.core.rolling.RollingFileAppender as class for your appender. A FileAppender can not roll.

I believe you're missing the %i parameter, which should be replaced by the rolling file index (i.e. 'mylog.2017-03-13.0.txt', 'mylog.2017-03-13.1.txt', etc.)
In addition, like Uwe Allner, I'm using RollingFileAppender instead of FileAppender.
(I also suggest adding a totalSizeCap to the configuration, in order to control to total size)
Here's my entire appender configuration:
<appender name="SQL_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_HOME}/mylog.txt</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level- %msg%n
</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<maxHistory>3</maxHistory>
<totalSizeCap>5GB</totalSizeCap>
<fileNamePattern>${LOG_HOME}/archived/mylog.%d{yyyy-MM-dd}.%i.txt.zip</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>20MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>

Related

Time and size based logger backup policy

I am trying to create logger policy in a spring based project.
In below logger I wish to created a rolling policy which creates a new file when rollingfile.log exceds more than 10 Mb. So I can have backup of logs without having one single huge logger file. Is there any way to do that?
Given below is my logback.xml.
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true" scan="true" scanPeriod="30 seconds">
<property name="LOG_PATH" value="D:/coinLogs" />
<property name="LOG_ARCHIVE" value="${LOG_PATH}/archive" />
<appender name="Console-Appender" class="ch.qos.logback.core.ConsoleAppender">
<layout>
<pattern>[%d{yyyy-MM-dd HH:mm:ss}] - [%X{requestId}] - %p %c -- %m%n
</pattern>
</layout>
</appender>
<appender name="File-Appender" class="ch.qos.logback.core.FileAppender">
<file>${LOG_PATH}/logfile.log</file>
<encoder>
<pattern>[%d{yyyy-MM-dd HH:mm:ss}] - [%X{requestId}] - %p %c -- %m%n
</pattern>
<outputPatternAsHeader>true</outputPatternAsHeader>
</encoder>
</appender>
<appender name="RollingFile-Appender"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/rollingfile.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_ARCHIVE}/rollingfile.log%d{yyyy-MM-dd}.log
</fileNamePattern>
<maxHistory>30</maxHistory>
<totalSizeCap>10MB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%msg%n</pattern>
</encoder>
</appender>
<appender name="Async-Appender" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="RollingFile-Appender" />
</appender>
<logger name="coinPay.logbackxml" level="info" additivity="false">
<appender-ref ref="Console-Appender" />
<appender-ref ref="File-Appender" />
<appender-ref ref="Async-Appender" />
</logger>
<!-- To remove extra hibernate logs -->
<logger name="org.hibernate">
<level value="info" />
</logger>
<root>
<appender-ref ref="Console-Appender" />
<appender-ref ref="File-Appender" />
<appender-ref ref="Async-Appender" />
</root>
</configuration>
The total size cap is not doing what you want.
<totalSizeCap>10MB</totalSizeCap>
It caps the total size of all your archived log files. You could have a look at TimeBasedArchiveRemover::capTotalSize to understand what it is doing.
What you need to do is change TimeBasedRollingPolicy to SizeAndTimeBasedRollingPolicy and set <maxFileSize>10MB</maxFileSize>
So your configuration should include:
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_ARCHIVE}/rollingfile.log%d{yyyy-MM-dd}.log
</fileNamePattern>
<maxFileSize>10MB<maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>

Logback configuration into Java project

I'm using logback to save all my INFO into log file and every day I would like to save this file in a specific folder archived
This is how I have configured it:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
</Pattern>
</layout>
</appender>
<appender name="FILE-AUDIT"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${CATALINA_HOME}/logs/DartFleetViewer.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} - %msg%n
</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${CATALINA_HOME}/logs/archived/DartFleetViewer.%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>
<!-- <appender name="FILE-ERROR"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${DEV_HOME}/error.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} - %msg%n
</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
rollover daily
<fileNamePattern>${DEV_HOME}/archived/error.%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender> -->
<!-- Send logs to both console and file audit -->
<root level="info">
<appender-ref ref="FILE-AUDIT" />
<appender-ref ref="STDOUT" />
</root>
<!-- <root level="error">
<appender-ref ref="FILE-ERROR" />
</root> -->
</configuration>
The odd thing is that I find this in my folder
almost all of the files are empty or with few code lines, for example I don't find nothing about yesterday, In the last file I only find
2016-08-02 02:18:06 - SCHEDULED ACTIVITY TO DELETE OLD NOTIFICATIONS
2016-08-02 05:18:06 - SCHEDULED ACTIVITY TO DELETE OLD NOTIFICATIONS
2016-08-02 08:18:06 - SCHEDULED ACTIVITY TO DELETE OLD NOTIFICATIONS
This is information about today and not yesterday.
Furthermore yesterday I had some errors, warnings and a lot of info log.
Do you see some error in my configuration file?
UPDATE:
Since I receive warning during deployment I have changed my logback configuration in order to avoid all warning and I use only time rollback. It seems to work:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
</Pattern>
</encoder>
</appender>
<appender name="FILE-AUDIT"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${CATALINA_HOME}/logs/DartFleetViewer.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${CATALINA_HOME}/logs/archived/DartFleetViewer.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
<totalSizeCap>10GB</totalSizeCap>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>
%d{yyyy-MM-dd HH:mm:ss} - %msg%n
</pattern>
</encoder>
</appender>
<!-- Send logs to both console and file audit -->
<root level="info">
<appender-ref ref="FILE-AUDIT" />
<appender-ref ref="STDOUT" />
</root>
<!-- <root level="error">
<appender-ref ref="FILE-ERROR" />
</root> -->
</configuration>

Cassandra Java driver logging

We are using logback as the logging framework for our java project... The logback configuration is as given below
<configuration debug="true">
<property name="LOG_HOME" value="/etc/report-synchronizer" />
<appender name="SIFT" class="ch.qos.logback.classic.sift.SiftingAppender">
<discriminator>
<key>modulename</key>
<defaultValue>unknown</defaultValue>
</discriminator>
<sift>
<appender name="FILE-${modulename}"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${LOG_HOME}/${modulename}-%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 5MB -->
<maxFileSize>5MB</maxFileSize>
<!-- Number of days for which the files will be kept -->
<maxHistory>10</maxHistory>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d [%thread] %level %mdc %logger{35} - %msg%n</pattern>
</layout>
</appender>
</sift>
</appender>
<root level="DEBUG">
<appender-ref ref="SIFT" />
</root>
</configuration>
We are using java cassandra driver in the project. All the logs generated by the cassandra driver are getting mixed up with our application logs. Is there any way to separate the cassandra driver logs to a separate file
Thanks in advance
Declare a logger with name com.datastax.driver, a dedicated appender, and additivity set to false. This way you will confine the driver logs to its appender.
The following example should give you a good start:
<logger name="com.datastax.driver" level="INFO" additivity="false">
<appender-ref ref="DRIVER"/>
</logger>
<appender name="DRIVER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_HOME}/${modulename}-driver.log</file>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d [%thread] %level %mdc %logger{35} - %msg%n</pattern>
</layout>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${LOG_HOME}/${modulename}-driver-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 5MB -->
<maxFileSize>5MB</maxFileSize>
<!-- Number of days for which the files will be kept -->
<maxHistory>10</maxHistory>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>

Logback stopped logging after splitting shared config file

I have introduced logback to a system that uses muliple JVM's. The system is in fact two seperate projects, and previously they shared an external configuration file that looked like this:
<?xml version="1.0" encoding="UTF-8" ?>
<configuration scan="true">
<!-- general console appender -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d{HH:mm:ss.SSS,CET} %-5level [%file:%line] - %msg%n</pattern>
</layout>
</encoder>
<target>System.out</target>
</appender>
<!-- Project1 appenders -->
<appender name="project1ApplicationAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<prudent>true</prudent>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>/data/logs/project1/application/%d{yyyy-MM-dd}/application.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 100MB -->
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- keep 90 days' worth of history -->
<maxHistory>90</maxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>[%-5p] [%d{dd.MM.yyyy - HH.mm.ss.SSS,CET}] [%C{1} - %L] %X{ClientTraceId} %X{CallSequenceTrace} %m%n</Pattern>
</layout>
</encoder>
</appender>
<appender name="project1ConnectorAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<prudent>true</prudent>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>/data/logs/project1/connector/%d{yyyy-MM-dd}/connector.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 100MB -->
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- keep 90 days' worth of history -->
<maxHistory>90</maxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>[%d{dd.MM.yyyy - HH.mm.ss.SSS,CET}] %m%n</Pattern>
</layout>
</encoder>
</appender>
<!-- project1 loggers -->
<logger name="logger1project1" additivity="false">
<level value="ALL"/>
<appender-ref ref="project1ConnectorAppender"/>
</logger>
<logger name="logger2project1">
<level value="INFO"/>
<appender-ref ref="project1ApplicationAppender"/>
</logger>
<logger name="logger3project1">
<level value="INFO"/>
<appender-ref ref="project1ApplicationAppender"/>
</logger>
<!-- project2 appenders -->
<appender name="project2ApplicationAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<prudent>true</prudent>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>/data/logs/project2/application/%d{yyyy-MM-dd}/application.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 100MB -->
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- keep 90 days' worth of history -->
<maxHistory>90</maxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>[%-5p] [%d{dd.MM.yyyy - HH.mm.ss.SSS,CET}] [%C{1} - %L] %X{ClientTraceId} %X{CallSequenceTrace} %m%n</Pattern>
</layout>
</encoder>
</appender>
<appender name="project2ConnectorAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<prudent>true</prudent>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>/data/logs/project2/connector/%d{yyyy-MM-dd}/connector.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 100MB -->
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- keep 30 days' worth of history -->
<maxHistory>90</maxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>[%d{dd.MM.yyyy - HH.mm.ss.SSS,CET}] %m%n</Pattern>
</layout>
</encoder>
</appender>
<!-- project2 loggers -->
<logger name="logger1project2" additivity="false">
<level value="OFF"/>
<appender-ref ref="project2ConnectorAppender"/>
</logger>
<logger name="logger2project2">
<level value="INFO"/>
<appender-ref ref="project2ApplicationAppender"/>
</logger>
<root>
<level value="INFO"/>
<appender-ref ref="console"/>
</root>
</configuration>
This worked like it should.
Then we introduced a new logger that had the same name in both projects, but we still wanted separate files for each project, so we had to split the config file into two.
When we did that, one of the projects stopped logging, and i cannot understand why. This is the configuration file for the project that stopped:
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true">
<!-- general console appender -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d{HH:mm:ss.SSS,CET} %-5level [%file:%line] - %msg%n</pattern>
</layout>
</encoder>
<target>System.out</target>
</appender>
<!-- project2 appenders -->
<appender name="project2ApplicationAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<prudent>true</prudent>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>/data/logs/project2/application/%d{yyyy-MM-dd}/application.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 100MB -->
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- keep 90 days' worth of history -->
<maxHistory>90</maxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>[%-5p] [%d{dd.MM.yyyy - HH.mm.ss.SSS,CET}] [%C{1} - %L] %X{ClientTraceId} %X{CallSequenceTrace} %m%n</Pattern>
</layout>
</encoder>
</appender>
<appender name="project2ConnectorAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<prudent>true</prudent>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>/data/logs/project2/connector/%d{yyyy-MM-dd}/connector.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 100MB -->
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- keep 90 days' worth of history -->
<maxHistory>90</maxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>[CBM - %-5p] [%d{"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"}] %m%n</pattern>
</layout>
</encoder>
</appender>
<appender name="project2PayloadAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<prudent>true</prudent>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>/data/logs/project2/payload/%d{yyyy-MM-dd}/payload.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 100MB -->
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- keep 90 days' worth of history -->
<maxHistory>90</maxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>[CBM - %-5p] [%d{"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"}] %m%n</pattern>
</layout>
</encoder>
</appender>
<!-- project2 loggers -->
<logger name="logger1project2" additivity="false">
<level value="INFO" />
<appender-ref ref="project2ConnectorAppender" />
</logger>
<logger name="newlogger" level="TRACE" additivity="false">
<appender-ref ref="project2PayloadAppender" />
</logger>
<logger name="logger2project2" additivity="false">
<level value="DEBUG" />
<appender-ref ref="project2ApplicationAppender" />
</logger>
<root>
<level value="INFO" />
<appender-ref ref="project2ApplicationAppender" />
</root>
</configuration>
I have added the specific paths in the java options in each JVM like this:
-Dlogback.configurationFile={config path}
They were previously the same for each project, but are now separate.
One other piece of information is that the system is deployed on two servers, each with a copy of the config files. And it works perfectly on one of the servers, even tho the config files and deployment process are identical.
I have looked for solutions for an entire workday without any luck.
This is in a live production environment, so i cannot simply do a new deploy of the system, or read status messages from console.
We have test systems, but the issue is not present there, even tho the config files are similar.
Thanks for any answers in advance!

Rolling logback logs on filesize and time

I've been trying to set up a simple logback project to roll my log files by date and by filesize, and so far I have been unable to get my appender to roll over to another file. Instead, it writes to the log specified by the <file/> tag.
Here is my logback.xml configuration file:
<?xml version="1.0"?>
<configuration scan="true" scanPeriod="10 seconds">
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
</layout>
</appender>
<appender name="milliroller" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>log/output.log</file>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
</layout>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>log/mylog-%d{yyyy-MM-dd}.%i.txt</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>1KB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<root level="DEBUG">
<appender-ref ref="stdout"/>
<appender-ref ref="milliroller"/>
</root>
<logger name="com.tkassembled.logback" level="DEBUG"/>
</configuration>
At first glance, it looks like it should work, right? Is there something I'm doing wrong? My entire, buildable project is available in a zip here: http://www.mediafire.com/file/2bxokkdyz2i/logback.zip
Although this is an old question, I felt that a working answer is appropriate to help anyone who requires this kind of implementation.
I use the following logback configuration to provide an HTML log, rolled over by date and filesize, as well as logging to console for debugging output.
Logfiles are stored in a logs directory with a name of logFile.html while its active, and logFile.2013-mm-dd.i.html when it rolls over, where i is the number of 50MB log files. For instance logFile.2013-01-07.0.html.
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<charset>UTF-8</charset>
<pattern>%d{HH:mm:ss.SSS} [%thread] %highlight(%-5level) %cyan(%logger{35}) - %msg %n</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs\logFile.html</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>logs\logFile.%d{yyyy-MM-dd}.%i.html</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 50MB -->
<maxFileSize>50MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- keep 30 days' worth of history -->
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<charset>UTF-8</charset>
<layout class="ch.qos.logback.classic.html.HTMLLayout">
<pattern>%d{HH:mm:ss.SSS}%thread%level%logger%line%msg</pattern>
</layout>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>
Since logback 1.1.7 (released March 2016) a new policy called SizeAndTimeBasedRollingPolicy is available that dramatically simplifies what you need to do:
<appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>app.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>app-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%msg%n</pattern>
</encoder>
</appender>
See here for further info.

Categories