Search code examples
javajetty

How to control log rotation for Jetty Runner web apps


I'm using jetty-runner.jar version 9.4.28.v20200408. When I run java jar command, I got this output:

Usage: java [-Djetty.home=dir] -jar jetty-runner.jar [--help|--version] [ server opts] [[ context opts] context ...]

and the server opts include this entry

 --out file                          - info/warn/debug log filename (with optional 'yyyy_mm_dd' wildcard

So I have used this expression

yyyy_mm_dd_${API_NAME}-${PORT}-http.log

The logging is working with yyyy_mm_dd but the old entries can't be deleted automatically. Is there a way I can control this?


Solution

  • Note: jetty-runner is deprecated and is being removed.

    https://github.com/eclipse/jetty.project/commit/a1b38fadb836f768af6a2cb348d1687715381b25

    jetty-runner is for quick testing of your webapp, and is not recommended for production use, purely because it's not setup for customization and configuration just like you are experiencing now.

    It's essentially a hardcoded configuration, with a scant few knobs you can tweak.

    Logging is hardcoded to use internal Jetty StdErrLog and Jetty RolloverFileOutputStream. Neither of which support what you are attempting to do.

    If you move to pure embedded-jetty, where you control things, or use the proper ${jetty.home} and ${jetty.base} split, then you can specify any slf4j based logging implementation you want, along with all of the custom logging behaviors you need (rollover, compression, triggers for rollover, old rollover file behaviors, etc).