2

I'm using tomcat 7 on a virtual machine running Ubuntu. Right now, I have a catalina.out file at /var/lib/tomcat7/logs/catalina.out that is over 20GB in size. I tried first rotating the log file through this tutorial. I then found out that it will monitor it at the end of the night. Even starting the service manually didn't really do much. So I removed the file, but it appeared after I restarted tomcat.

I then tried doing what the accepted answer here was which was to go into conf/logging.properties and change the following line from:

.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler

to

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

This seems to have worked for a minute, at least until I re-started my virtual machine. Once that happened, I ended up with another 20GB catalina.out file.

Is there some proven way that will either stop the file from getting above 5MB or will just limit the file at all?

Community
  • 1
  • 1
Alex
  • 2,049
  • 4
  • 33
  • 69
  • You should have a deep look into [logging in java](https://docs.oracle.com/javase/8/docs/technotes/guides/logging/overview.html) and [logging with Tomcat](http://tomcat.apache.org/tomcat-7.0-doc/logging.html). – Stefan Apr 20 '16 at 07:48
  • http://stackoverflow.com/questions/8342336/how-to-set-maximum-number-of-rolls-and-maximum-log-size-for-tomcat – Stefan Apr 20 '16 at 07:52

1 Answers1

-1

As 'Stefan' pointed out you can use the standard java.util.logging.FileHandler instead of the one included with Tomcat.

By default the org.apache.juli.FileHandler level is set to ALL. You can try to raise the handler log level to filter groups of debug type messages.

.handlers = 1catalina.org.apache.juli.FileHandler
1catalina.org.apache.juli.FileHandler.level=WARNING
#1catalina.org.apache.juli.FileHandler.level=OFF

Otherwise it looks like you have to write a custom filter and install it on the handler by setting the .filter property.

public class FileLengthFilter implements Filter {

    private final File target;
    private final long limit;

    public FileLengthFilter() {
        final String p = getClass().getName();
        LogManager lm = LogManager.getLogManager();
        String v = lm.getProperty(p + ".file");
        target = new File(v == null ? "." : v);

        v = lm.getProperty(p + ".limit");
        long l;
        try {
            l = Long.parseLong(v);
        } catch (RuntimeException re) {
            l = 5L * 1024L * 1024L;
        }
        this.limit = l;
    }

    @Override
    public boolean isLoggable(LogRecord record) {
        try {
            return target.length() <= limit;
        } catch (RuntimeException se) {
            return false;
        }
    }
}
Community
  • 1
  • 1
jmehrens
  • 9,782
  • 1
  • 33
  • 45