SRI PRIYA
SRI PRIYA

Reputation: 21

Create new STDOUT or STDERR log when size hit 20MB size?

I am using Tomcat 8 to run application in Window 10 (Run as window service).

I would like to confirm how should I avoid the STDOUT or STDERR log file to be too big by any of two approach below:

Create new STDOUT or STDERR log when size hit 20MB size? Is there any way to achieve on any approach above?

Upvotes: 2

Views: 1114

Answers (1)

Piotr P. Karwasz
Piotr P. Karwasz

Reputation: 16105

Short answer: you can't.

While theoretically Procrun (the executable, which launches Tomcat as a Window service) could regularly redirect the standard output and error streams to a new file (using techniques like in this question), in practice it doesn't: the redirection of the standard streams is performed only once during startup.

There are some hints in the source code that a time-based rotation feature was considered in Procrun (cf. github), but it was never implemented. You might add a feature request to the project's JIRA.

The best solution available today is don't send your logs to stdout/stderr. All proper logging frameworks implement some sort of rotating logfiles.

In Tomcat's case you just need to:

  1. Disable the ConsoleHandler in the logging.properties file by replacing the .handlers line with:
    .handlers = 1catalina.org.apache.juli.AsyncFileHandler
    
    The remaining handler writes to catalina.<date>.log and is rotated daily.
  2. Redirect all output sent to System.out/System.err to the handler above, by setting swallowOutput="true" in context.xml:
    <Context swallowOutput="true">
        ...
    </Context>
    
  3. If your applications use a different logging framework from java.util.logging (e.g. Log4j, Logback) configure the logging system to log to a file instead of the console.

Upvotes: 2

Related Questions