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.
The JDK Logging Adapter is a custom implementation of java. util. logging. LogManager that uses Log4j.
A Logger object is used to log messages for a specific system or application component. Loggers are normally named, using a hierarchical dot-separated namespace. Logger names can be arbitrary strings, but they should normally be based on the package name or class name of the logged component, such as java.net or javax.
may this example will helps you.
String timeStamp = new SimpleDateFormat().format( new Date() );
FileHandler fh = new FileHandler("./jay_log_%u.%g_" +timeStamp +".log", 30000,4);
logger.addHandler(fh);
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With