1
votes

I recently followed this tomcat article to change my stdout log appearance while using log4j. I wanted a time stamp for each action a user takes. After following the article, I am still not receiving the desired result. The tomcat 8 stdout log looked like:

(action.BaseAction 39 ) Calling Action /editBlaBlaBla by: System Administrator

However I wanted to add a timestamp to each action a user takes. IE:

(action.BaseAction 2015/07/26 15:46:12 39 ) Calling Action /editBlaBlaBla by: System Administrator

After adding the necessary jars (tomcat-juli, tomcat-juli-adapter, and log4j) to Tomcat 8.0\lib directory and adding a log4j properties file beside my logging.properties in Tomcat 8.0\conf directory.

My stdout logs look like:

2016-02-26 10:38:18 Commons Daemon procrun stdout initialized running
ControllerServlet init
Running ControllerServlet tempInit

There are no entries corresponding to user actions.
My log4j.properties file:

log4j.rootLogger=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 [%-6p] %c{1} - %m%n

This is how the logger is initialized in my java action classes

import org.apache.log4j.Logger;
private static final Logger logger = Logger.getLogger(MYCLASSHERE.class);

How do I go about getting the time stamp without redoing the entirety of my java logging statements?

1

1 Answers

0
votes

Try this.

log4j.appender.stdout.layout.ConversionPattern=%-d{MMM dd yyyy HH:mm:ss} %-5p %C{1} %M %m%n

And your output will be like

Feb 22 2016 15:52:22 INFO ClassName MethodName StringInLogDotInfo