0

I migrated a small REST API application to Helidon MP which is using java.util.logging. I try to configure a rolling file appender which simply creats a new file per calendar day.

The app previously used Log4j2 where this was possible, but I cannot find a way how to do this with the java.util.logging.FileHandler. It seems only to be able to rotate by file size, see below:

java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.FileHandler.pattern=c:/temp/logs/fwa.log
java.util.logging.FileHandler.limit=50000
java.util.logging.FileHandler.count=1

I would like to have the following:

  • fwa.log
  • fwa.log.YYYY-MM-DD
  • etc.

I get:

  • fwa.log.0
  • fwa.log.1
  • fwa.log.2
  • etc.
Mrvonwyl
  • 347
  • 2
  • 15
  • An alternative might be to remove 'java.util.logging' from Helidon and use Log4j, but i can't find any information on that either. – Mrvonwyl Jul 26 '19 at 14:30
  • ['*`java.util.logging.FileHandler.pattern` specifies a pattern for generating the output file name. See below for details. (Defaults to `"%h/java%u.log"`).*'](https://docs.oracle.com/javase/7/docs/api/java/util/logging/FileHandler.html) –  Jul 26 '19 at 14:31
  • You can use [JUL to SLF4J](https://mvnrepository.com/artifact/org.slf4j/jul-to-slf4j/1.7.26) to replace their logging framework with whatever you want, i.e. log4j or logback – Michael Jul 26 '19 at 14:38

2 Answers2

0

No, it is not possible directly.

You can either:

  1. Use an Adapter to direct the Logs to a different Framework. For example Log4j2 -> see LOG4j JUL adapter ...and make the configuration in LOG4J

  2. Write you own file handler as suggested in this answer enter link description here

0

SLF4J also has an adapter for JUL.

This allows you to add a SLF4J implementation, add the adapter for JUL (Java Util Logging), and configure any log rolling supported by the SLF4J implementation.

Logback is an SLF4J implementation that supports log rolling by date as well as rolling for other reasons.

DwB
  • 37,124
  • 11
  • 56
  • 82