
Hello, I presume your question is regarding the usage of a discriminator within SiftingAppender. Is that correct? If so, as you can see in the append() method [1] defined in SiftingAppenderBase, the discriminator is invoked for every append call. In my opinion, SiftingAppender may be too much for the problem at hand. A simpler alternative would be to schedule a periodic task which checks for changes in the system property and reconfigure logback when changes are detected. The code invoke Joran (logback's configirator) is described at http://logback.qos.ch/manual/configuration.html#joranDirectly I hope this helps, -- Ceki [1] https://github.com/qos-ch/logback/blob/master/logback-core/src/main/java/ch/... On 3/11/2016 10:25, DK wrote:
I'm trying to split logs based on a System property that changes dynamically at runtime. Is the below Discriminator code the way to go? Will this Discriminator get called for every log statement?
import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.sift.AbstractDiscriminator;
public class SysPropDiscriminator extends AbstractDiscriminator {
private static final String KEY = "PROP";
@Override public String getDiscriminatingValue(ILoggingEvent event) { String propValue = System.getProperty("my.property"); if (propValue == null || propValue.length() == 0) { return "unknown"; } else { return propValue; } }
@Override public String getKey() { return KEY; } }