Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j in tomcat not showing logs

This is my log4j.properties.

# Root logger option
log4j.rootLogger=INFO, file, stdout

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=${catalina.home}\MyLog\PmcDemo.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
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

# Direct log messages to stdout
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

I am using tomcat 6.0, in my application I have used Logger from log4j yet I don't see any output on server console or in the log file. My application is using struts2 as front end, Spring framework as middle layer and hibernate as the end layer. I don't see my application logging how can I enable it in tomcat 6?

like image 329
Bilbo Baggins Avatar asked Nov 29 '13 08:11

Bilbo Baggins


People also ask

Is log4j included in Tomcat?

Apache Tomcat. Log4j may be used as the logging framework for Apache Tomcat. This support is implemented automatically by including the log4j-api, log4j-core, and log4j-appserver jars in the boot classpath.

Where can I find log4j logs?

The Log4j logging settings are stored in the file app_data /conf/server/log4j. properties, where app_data is the application data folder. You can edit this file directly on the server or open it by clicking Settings > Logging.

How do I view tomcat logs?

The main Apache Tomcat configuration file is at /opt/bitnami/tomcat/conf/server. xml. Once Apache Tomcat starts, it will create several log files in the /opt/bitnami/tomcat/logs directory.

Where is tomcat log4j?

Log4j and Tomcat Libraries are placed in common library directory. The configuration file for Tomcat is in common/classes directory, the configuration file for a application is placed in the WEB-INF/classes folder of the application.


1 Answers

You need to switch the backslashes for forward slashes:

${catalina.home}/MyLog/PmcDemo.log

or to escape them

${catalina.home}\\MyLog\\PmcDemo.log

If that doesn't help, let us know the structure of your project and where the log4j.properties file is stored.

like image 61
cowls Avatar answered Sep 23 '22 05:09

cowls