NickJ
NickJ

Reputation: 9559

Log4j - Logger not working

I have a Log4j properties file with the following configuration:

log4j.rootLogger=INFO, A1

log4j.logger.metrics=INFO, METRICS

log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

log4j.appender.METRICS.layout=org.apache.log4j.PatternLayout
log4j.appender.METRICS.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

And the Java code:

private static Logger LOGGER = Logger.getLogger("com.me.MyClass");
private static Logger METRICS = Logger.getLogger("metrics");
...
LOGGER.info("This message appears");
METRICS.info("but this message does not appear");

As hinted, the log line send to the metrics logger never appears, and I'm at my wits' end trying to figure out why not. I have confirmed the line does get executed, and according to all the docs I've read, the config is correct as far as I can see. What am I missing?

Upvotes: 1

Views: 2967

Answers (2)

PeterMmm
PeterMmm

Reputation: 24630

What happens if you add this to your log4 configuration?

log4j.appender.METRICS=org.apache.log4j.ConsoleAppender

Upvotes: 2

sai
sai

Reputation: 75

Add below configurations and see.I think this may help you

log4j.rootLogger=INFO,METRICS
log4j.appender.METRICS=org.apache.log4j.ConsoleAppender

Upvotes: 0

Related Questions