How to stop Tomcat logging?
Solution 1
To stop access log (default tomcat setting) go to:
conf/server.xml
and remove the following config:
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
to disable common log, go to:
conf/logging.properties
and comment the following line
handlers = 1catalina.org.apache.juli.FileHandler, .....
Solution 2
Don't start Tomcat. No Tomcat, no logging.
On a more serious note, don't. Just don't. This sounds like a surefire recipe to cause problems when you're gone, not available or don't remember anymore what you did.
Instead, install a log rotator which deletes old log files after N days.
Also make sure that Tomcat doesn't write too much into catalina.out
since you can't rotate that.
For this, I patch the start script and pipe through head -10000
. Replace this
>> "$CATALINA_OUT" 2>&1 "&"
with
2>&1 | head -10000 >> "$CATALINA_OUT" &
If there is an error starting Tomcat, I'll still see it. But no more than 10'000 lines of log will be written to that file, so it won't grow forever.
Note: Simply deleting catalina.out
will not work. On Windows, it will fail since it's still open. On Unix, only the directory entry will be deleted (making the file inaccessible for anyone except processed which have it open). The file will still take up space on the hard disk and it will continue to grow.
Related articles:
Cacheing
Updated on June 04, 2022Comments
-
Cacheing almost 2 years
Tomcat automatically does its logging, and the logging files are all under
/logs
directory. As far as I know, the logging property is/conf/logging.properties
. How can I stop all the logging? -
Cacheing over 10 yearshelpdesk.objects.com.au/java/…. I used this method to disable writing logs to
catalina.out
, but it doesn't work. -
Cacheing over 10 yearsWill it work if I comment out the
handlers
line and.handlers
line in thelogging.properties
file? -
Aaron Digulla over 10 yearsPlease edit your question and add your
logging.properties
. Is Tomcat running on Windows or Linux? -
Aaron Digulla over 10 yearsOh, and which version of Tomcat?
-
Jonathan S. Fisher over 5 yearsIf you're running tomcat in a proper systemd unit with non-forking process, your logs will be handled automatically if put to stdout, so there is no need for a loggin configuration.
-
Juan Rojas almost 4 yearshow to prevent tomcat from writing too much into catalina.out? links are broken
-
Imaskar over 3 yearsThere might be legit cases to disable logging. For example if it's handled by a logging framework in the code.
-
Aaron Digulla over 3 years@Imaskar The problem with Tomcat is that it logs important errors which make it impossible to start your app BEFORE your app's log framework is even loaded.