Search code examples
javaweblog4jtomcat7ubuntu-16.04

log4j doesn't write in log file on tomcat7 (ubuntu server)


This is my log4j.properties file:

# LOG4J configuration
log4j.rootLogger=INFO, Appender1,Appender2
log4j.logger.org.hibernate=info
log4j.logger.org.quartz=info

log4j.appender.Appender1=org.apache.log4j.ConsoleAppender
log4j.appender.Appender1.layout=org.apache.log4j.PatternLayout
log4j.appender.Appender1.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n

log4j.appender.Appender2=org.apache.log4j.FileAppender
log4j.appender.Appender2.File=/home/diego/proyect/log/general.log
log4j.appender.Appender2.layout=org.apache.log4j.PatternLayout
log4j.appender.Appender2.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n

Locally works on my windows machine, but on the server (ubuntu 16.04) side the web application cannot write on the .log file, already modified permissions for the file:

chmod 777 /home/diego/proyect/log/general.log

this is the resuls of ls -lhs on the log directory:

-rwxrwxrwx 1 diego diego 0 Nov 16 14:23 general.log

Also not sure which is the tomcat user on the server.


Solution

  • I solved, it seems I need to add the log4j.properties files into the classpath, my project has the following structure:

    • main
      • src/main/java
      • src/main/resources/log4j.properties
      • webapp
        • WEB-INF/log4j.properties

    So I put the file under src/main/resources directory and it works.