Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify Tomcat logs as home for log4j log file

Tags:

My WAR is using a log4j FileAppender configured via a log4j.properties file under the classes/ directory inside the WAR.

I have configured my log4j appender as such:

# 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=MonitorLog.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 

With this configuration I am trying to achieve the following:

  • All log messages DEBUG-level and higher get logged (so everything)
  • I want the MonitorLog.log file to be located under Tomcat's logs/ directory

Does this configuration achieve these items, and if not, what needs to change?

like image 924
IAmYourFaja Avatar asked Jun 06 '12 17:06

IAmYourFaja


People also ask

Where is log4j properties file located in Tomcat?

The file is named log4j. properties and is located in the $DGRAPH_HOME/dgraph-hdfs-agent/lib directory. The file defines the ROLLINGFILE appenders for the root logger and also sets the log level for the file. The level of the root logger is defined as INFO and attaches the ROLLINGFILE appender to it.

Does Apache Tomcat use log4j by default?

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.

What is localhost log in Tomcat?

Localhost Log : This is the log for all HTTP transactions between the client and the application server. The log file is named as, localhost_access_log. <date of log generation>. txt file. The default location and rotation policy for this log is the same as catalina.


1 Answers

If you know this WAR will only be deployed to a tomcat, you can take advantage of the system property catalina.base, which represents the root of your tomcat base folder (there is also a cataline.home, but they are often the same unless you have multiple tomcats running on the same machine and are sharing the server libs, but i digress).

So update as follows:

log4j.appender.MonitorAppender.File=${catalina.base}/logs/MonitorLog.log 
like image 195
Chris White Avatar answered Sep 20 '22 16:09

Chris White