Thanks to your example, I implemented a loggername based discriminator solution that directs different log output to different files. Although the logback documentation is so detailed, I could not find this important information. You must have found the solution mentioned by yayitswei already.
logback.xml:
[...] <timestamp key="startTimestamp" datePattern="yyyy-MM-dd"/> <timestamp key="folderTimestamp" datePattern="MM-yyyy"/> <property name="LOGDIR" value="/var/log/spock" /> <appender name="SIFT" class="ch.qos.logback.classic.sift.SiftingAppender"> <discriminator class="com.enterprise.spock.LoggerNameBasedDiscriminator" /> <sift> <appender name="FILE-${loggerName}" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${LOGDIR}/${loggerName}-${startTimestamp}.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <fileNamePattern>${LOGDIR}/${folderTimestamp}/${loggerName}-%d{yyyy-MM-dd}-%i.log.gz</fileNamePattern> <maxFileSize>500KB</maxFileSize> <maxHistory>100</maxHistory> <totalSizeCap>50MB</totalSizeCap> </rollingPolicy> <encoder> <charset>UTF-8</charset> <pattern>%level %date{HH:mm:ss.SSS}: %msg %n</pattern> </encoder> </appender> </sift> </appender> [...]
Edit: I replaced TimeBasedRollingPolicy with the SizeAndTimeBasedRollingPolicy parameter suggested here . For this you need at least logback 1.1.7.
What you get with this is a log file for every Logger created. Each log file will look like this: /var/log/loggername-2017-08-03.log.
When about 500 KB has been written to the file, it will be archived as gz-zipfile in / var / log / loggername / 08-2017 / loggername-2017-08-03-0.log.gz.
0 at the end of gz-zipfile-name is %i from <fileNamePattern> above. Without %i this will not work. Remember to use <configuration debug=true> in logback.xml if something doesn't work.
source share