Home > other >  Spring Access Log rotation by day
Spring Access Log rotation by day

Time:10-14

I use an embedded Jetty server for a spring application. I tried to configure the access log to have one log file per day but all access log are added in one file.

In my application properties file :

server.jetty.accesslog.enabled=true
server.jetty.accesslog.append=true
server.jetty.accesslog.filename=/var/logs/access.log
server.jetty.accesslog.file-date-format=.yyyy-MM-dd
server.jetty.accesslog.retention-period=366

CodePudding user response:

That configuration is from an old, now deprecated, Request Log mechanism in Jetty.

For this old configuration, you MUST use the yyyy_MM_dd notation.

In other words ...

# This MUST contain `yyyy_MM_dd`
server.jetty.accesslog.filename=/var/logs/access_yyyy_MM_dd.log
# This MUST be `yyyy_MM_dd` (no other option is supported)
server.jetty.accesslog.file-date-format=yyyy_MM_dd

Jetty has moved to CustomRequestLog which formats the log output, and using an implementation of RequestLog.Writer to determine where this formatted log is written to.

The most common RequestLog.Writer choice is Slf4jRequestLogWriter which writes the formatted logs to a named slf4j-api location, which allows you to use your logging implementation of choice (logback, java.util.logging, commons-logging, log4j1, log4j2, etc) to configure and specify rolling in that logging implementation (eg: by size, time, other event, etc).

The only other implementation of RequestLog.Writer is the AsyncRequestLogWriter, which has the same filename and fileDateFormat rules are stated above.

See past answer on spring CustomRequestLog : https://stackoverflow.com/a/66079787/775715

  • Related