how to display date and time in tomcat catalina.out log file
Asked Answered
G

1

7

I need to display the date and time of actual log info within the catalina.out log file for my tomcat7 installation. From the web I found the solution of adding this line to the logging.properties file, but it does not work. I added the following:

1catalina.java.util.logging.SimpleFormatter.format=[%1$td.%1$tm.%1$tY %1$tH:%1$tM:%1$tS,%1$tL

Right now its just a bunch of data that has zero timestamps. I just want the standard yyyymmdd hhmmss that precedes the INFO or ERROR, etc. in the log output.

what is present right now in my logging.properties file is this (I added the last line obviously):

java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
1catalina.java.util.logging.SimpleFormatter.format=[%1$td.%1$tm.%1$tY %1$tH:%1$tM:%1$tS,%1$tL

The version I'm using is apache-tomcat-7.0.82.

Any help you can provide would be great, and thank you in advance.

Greatnephew answered 7/12, 2017 at 15:31 Comment(0)
E
2

This is what worked for me on Tomcat 7.0.99:

...
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.ConsoleHandler.encoding = UTF-8

# My special format:
java.util.logging.SimpleFormatter.format=%1$tF %1$tT [%4$-7s] %5$s %n
...

The first three lines are out of the box default settings. Just the last line defines SimpleFormatter. Logfile looks like this:

2020-02-03 11:55:26 [INFORMATION] Loaded APR based Apache Tomcat Native library [1.2.23] using APR version [1.7.0]. 
2020-02-03 11:55:26 [INFORMATION] APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true]. 
2020-02-03 11:55:26 [INFORMATION] OpenSSL successfully initialized [OpenSSL 1.1.1c  28 May 2019] 
2020-02-03 11:55:26 [INFORMATION] Initialisiere ProtocolHandler["http-apr-8080"] 
2020-02-03 11:55:26 [INFORMATION] Initialisiere ProtocolHandler["ajp-apr-8009"] 
2020-02-03 11:55:26 [INFORMATION] Initialization processed in 368 ms 
2020-02-03 11:55:26 [INFORMATION] Starting service [Catalina] 
2020-02-03 11:55:26 [INFORMATION] Starting Servlet Engine: Apache Tomcat/7.0.99 

For more information regarding SimpleFormatter see: Oracle Java Documentation - SimpleFormatter and for Formatter see: Oracle Java Documentation - Formatter.

You can even change Tomcat logging to log4j (see: Tomcat - Using_Log4j) but that needs some more effort and would be an overkill for my simple use case.

Entryway answered 3/2, 2020 at 12:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.