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?
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:
ConsoleHandlerin thelogging.propertiesfile by replacing the.handlersline with: The remaining handler writes tocatalina.<date>.logand is rotated daily.System.out/System.errto the handler above, by settingswallowOutput="true"incontext.xml:java.util.logging(e.g. Log4j, Logback) configure the logging system to log to a file instead of the console.