I was able to get it to work by creating my own formatter using an example I found:
Java FileHandler to use 24 hour time
-
28-11-2021 - |
Frage
I have a FileHandler set up:
Logger logger = Logger.getLogger(this.class.getName());
FileHandler handler = new FileHandler(myFile, true);
handler.setFormatter(new SimpleFormatter());
logger.addHandler(handler);
logger.setUseParentHandlers(false);
However my server is in UTC, so in my log file, the timestamps look like: Nov 9, 2012 5:12:17 PM
This is harder to understand in a pinch, so I would like to know if it is possible
1) To convert this to 24 hour time, so at least I would see 17:12:17
instead of 5:12:17PM
2) To instead use a different time zone
I think it might be something about how I set up the formatter, but I just don't know how.
Thank you!
Lösung 2
Andere Tipps
I suggest you to read the javadoc of SimpleFormatter.format(), you may specify your own format via java.util.logging.SimpleFormatter.format property in the application logging configuration file.
The default properties file is <Java home>\jre7\lib\logging.properties. Copy it and put it wherever you want.
The Java Logging Overview is a good reading too.
The following code
System.setProperty(
"java.util.logging.SimpleFormatter.format", "%4$s: %5$s [%1$tc]%n" );
Logger l = Logger.getLogger("");
l.warning( "Hello" );
outputs
WARNING: Hello [ven. nov. 09 20:26:30 CET 2012]