Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j doesn't write logs to file

Tags:

java

log4j

I'm using slf4j over log4j.

     <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.12</version>
        </dependency>
     <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.12</version>
     </dependency>

The log4j.properties is in WEB-INF folder and has the following content:

log4j.rootLogger=DEBUG, stdout, file

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=D:\\logs\\log4j.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

On another enviroment with same version of Tomcat the same respository works just fine, logging to the file...

like image 310
Misca Avatar asked Aug 13 '15 14:08

Misca


1 Answers

You said that this same configuration file was working fine on a different environment. Can you give a little detail on the differences between the environments. e.g. are they both on Windows? The fact that is was working fine on another environment suggests that your configuration is fine, but there is some issue with your environment. Here are a few things to check:

  • Does the tomcat process has permissions to write to that file - i.e. are administrator rights required to write to D:\logs\log4j.log?

  • Make sure that there aren't any temporary files lying around tomcat's directories which may be preventing your changes from taking effect. To be sure, stop tomcat, delete the expanded war from %CATALINA_HOME%\webapps, delete the contents of %CATALINA_HOME%\temp and %CATALINA_HOME%\work

  • Check that you don't have any other log4j config files on your classpath, as these could be overriding your log4j file and preventing it from taking effect. To double check this, you could try temporarily removing your log4j.properties file to see if you get messages saying that the logging system is not initialised properly.

like image 166
olambert Avatar answered Sep 27 '22 23:09

olambert