HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How to redirect tomcat logs TO console?

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
tomcatlogsredirecthowconsole

Problem

So I have a problem that is the reverse of what everyone else on the internet wants.. I want to take tomcat logs that are being written out to /usr/local/tomcat/logs and have them be output to console instead. (Everyone else is asking the reverse.. how to get things away from console and to file). Reason why is because I'm on a system that captures output to console and directs it to an analytics program, it has to go to this program, and I have no control over how this is designed (ie. I can't change the program or capture process to use files as well as console).

To clarify, I am doing this on a Linux system, specifically Alpine.

Solution

There is Tomcat configuration file for the logging: TOMCAT_HOME/conf/logging.properties.
Edit the file and remove all the handlers except the console handler:

.handlers = java.util.logging.ConsoleHandler


This will direct all logging to the console, except for access logs (localhost_access_log.XXXX.txt). It is always written to file by the AccessLogValve, configured in 'server.xml'. To redirect that one you need to configure own implementation of the AbstractAccessLogValve... which requires coding.

Code Snippets

.handlers = java.util.logging.ConsoleHandler

Context

StackExchange DevOps Q#5256, answer score: 2

Revisions (0)

No revisions yet.