4

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.

2 Answers 2

3

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.

1

That doc say next:

When running Tomcat on unixes, the console output is usually redirected to the file named catalina.out. The name is configurable using an environment variable. (See the startup scripts). Whatever is written to System.err/out will be caught into that file. That may include:

Uncaught exceptions printed by

  • java.lang.ThreadGroup.uncaughtException(..)

  • Thread dumps, if you requested them via a system signal

When running as a service on Windows, the console output is also caught and redirected, but the file names are different.

The default logging configuration in Apache Tomcat writes the same messages to the console and to a log file. This is great when using Tomcat for development, but usually is not needed in production.

So if you need to catch the same logs which catch analytic software you need read catalina.out file.

Think it's will be helpful to you.

1
  • 1
    catalina.out already goes to console... I'm looking to find a way to get localhost.log and catalina.log out to console too. Commented Nov 2, 2018 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.