Currently I am using using Java util for logging logs into the file which can be configured from java.util.logging.FileHandler.pattern
. I want to append a timestamp in the log file name. I also have to take the log file path from java.util.logging.FileHandler.pattern
property.
Appending TimeStamp in log file name of Java util logger
Asked Answered
I hope you're using slf4j as a logging facade? –
Riverside
Use log4j :) and few more chars to satisfy minimum. –
Mucilage
You can reuse the FileHandler from Tomcat, it timestamps the filename and rolls it every day:
http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/juli/FileHandler.html
https://github.com/apache/tomcat/blob/7.0.x/java/org/apache/juli/FileHandler.java
public static String currentTimestamp() {
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
DateFormat f = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
return f.format(c.getTime());
}
this gives you back a timestamp
Have a look at this post, explain logging in details.
You can use %t
for time in your config file.
Link no longer exists. java.util.logging.FileHandler does not support %t –
Embolden
That's even the temp directory now (/tmp) –
Oestrogen
docs.oracle.com/javase/7/docs/api/java/util/logging/… says: "%t" the system temporary directory –
Barron
© 2022 - 2024 — McMap. All rights reserved.