System property based Discriminator

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; }} -- View this message in context: http://logback.10977.n7.nabble.com/System-property-based-Discriminator-tp147... Sent from the Users mailing list archive at Nabble.com.

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; } }

Yes it's a Discriminator for a SiftingAppender. I'll take a look at the Joran approach. For cases where the system property doesn't change. Is there a method in Discriminator for one-time setup of the property (i.e. one-time call to System.getProperty("my.prop")). Or is there another means to name log files based on a jvm system property? -- View this message in context: http://logback.10977.n7.nabble.com/System-property-based-Discriminator-tp147... Sent from the Users mailing list archive at Nabble.com.

http://logback.qos.ch/manual/configuration.html#variableSubstitution -- View this message in context: http://logback.10977.n7.nabble.com/System-property-based-Discriminator-tp147... Sent from the Users mailing list archive at Nabble.com.
participants (3)
-
Ceki Gulcu
-
DK
-
yihtserns