简体   繁体   中英

How to stop Tomcat logging?

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?

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 &quot;%r&quot; %s %b" />

to disable common log, go to:

conf/logging.properties

and comment the following line

handlers = 1catalina.org.apache.juli.FileHandler, .....

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM