Java – slf4j log4j recorder does not record
I want to use slf4j-log4j for the first time In each Java class, I define such a recorder:
private org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(<TheClass>.class);
(of course, I make sure that the slf4-log4j12-1.6.4. Jar jar is on the classpath!)
But whenever I use a logger, such as logger Debug ("something interesting happened"); Or logger Error ("an error occurred"); I can't see their output in the log file However, no exceptions occur and the application (which is actually a war deployed to Tomcat) runs normally
This is log4j. Net included in the project Properties file:
# Set the root logger to DEBUG. log4j.rootLogger=DEBUG # MonitorLog - used to log messages in the Monitor.log file. log4j.appender.MonitorAppender=org.apache.log4j.FileAppender log4j.appender.MonitorAppender.File=${catalina.base}/logs/MyAppMonitor.log log4j.appender.MonitorAppender.layout=org.apache.log4j.PatternLayout log4j.appender.MonitorAppender.layout.ConversionPattern= %-4r [%t] %-5p %c %x - %m%n # Use the MonitorAppender to log all messages. log4j.logger.*=DEBUG,MonitorAppender org.quartz.impl.StdSchedulerFactory=DEBUG,MonitorAppender
This war uses quartz to do some work, which is why you see the last entry
When I checked Tomcat's logs / directory, I saw that myappmonitor.com was created Log, but it has nothing (0 bytes) I've scanned all the typical Catalina Out, Catalina - and localhost - logs, and I don't see sunlight in my log statements
I was thinking:
>I did not configure log4j correctly Properties, or > I don't configure slf4j-log4j correctly, or > this is a classpath problem. Maybe war can't find log4j Properties (although I think I will see errors or warnings), or > I don't use slf4j correctly (API itself), or > I've never really created a thing called monitorappender, so I want to know if this is a problem; I just follow an example I saw on the Internet
Can anyone find where I'm going or help me troubleshoot? Thank you in advance!
Solution
Your log4j The properties configuration file contains many errors Try the following simple things
log4j.debug=true log4j.rootLogger=DEBUG,CON log4j.appender.CON=org.apache.log4j.ConsoleAppender log4j.appender.CON.layout=org.apache.log4j.PatternLayout log4j.appender.CON.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
For the configuration file in your question, the root logger does not have an appender attached And, yes
log4j.logger.*=DEBUG,MonitorAppender
Invalid because '*' is not supported