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:
- 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.
- Redirect all output sent to
System.out/System.err
to the handler above, by setting swallowOutput="true"
in context.xml
:
<Context swallowOutput="true">
...
</Context>
- 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.