[logback-user] separate task log files (slf4j + logback)

Ceki Gulcu ceki at qos.ch
Wed Oct 18 10:28:44 CEST 2017

Hello Denis,

The SiftingAppender uses a "discriminator" to sift events. This 
discriminator *can* be based on any part of the logging event and in 
particular the logger name.

Here is an example of a possible LoggerBasedDiscriminator:

package org.example;

public class LoggerBasedDiscriminator extends
    AbstractDiscriminator<ILoggingEvent> {

      private String key;

      public void start() {
        if (OptionHelper.isEmpty(key)) {
            addError("The \"Key\" property must be set");
            started = false;
        } else {
          started = true;


     public String getDiscriminatingValue(ILoggingEvent event) {
   	  return event.getLoggerName();

      public String getKey() {
           return key;

      public void setKey(String key) {
           this.key = key;


Here is an example configuration for the sifting appender:

  <appender name="SIFT"
     <discriminator class="org.example.LoggerBasedDiscriminator ">
       <appender name="FILE-${task}"
         <layout class="ch.qos.logback.classic.PatternLayout">
           <pattern>%d [%thread] %level %logger{35} - %msg%n</pattern>

As far as I can tell, the above is fits your initial requirements. 
However, I have not tested the above which might not even compile.


On 18.10.2017 08:41, Денис Матвеев wrote:
> The MDC does not help when I have several different long-running tasks
> in one thread and I just want to immediately separate their logs. It
> seems that this is not such a fantastic wish. It is much easier to
> separate logical logging flows at once, than to filter them later in
> databases. The amount of data is large, logs per day can accumulate
> several hundred megabytes. It turns out that we will have to write our
> own implementation of such a log.

More information about the logback-user mailing list