开发者

How to add time pattern in the log when using java logger

开发者 https://www.devze.com 2023-03-31 01:02 出处:网络
We use java.util.logging, and we use java.util.logging.FileHandler to config the rotated logs. We want to add timestamp into log file name pattern to make it looks like:

We use java.util.logging, and we use java.util.logging.FileHandler to config the rotated logs.

We want to add timestamp into log file name pattern to make it looks like:

logFile_2011-08-25_14_*02*_38_PDT.0.log
logFile_2011-08-25_14_*12*_38_PDT.1.log
logFile_2011-08-25_14_*22*_38_PDT.2.log
logFile_2011-08-25_14_*32*_38_PDT.3.log

Be aware of the different timestamp in the log file name.

We are now using the pattern = "logfile_XXXXXX.%g"

How is the pattern looks like to make the timestamp decided at runti开发者_如何学编程me?


No, java.util.logging no! Check out LogBack instead! It's a successor of log4j and of course implements sfl4j.

Back to your question, I'm not an expert of Java Logging but I believe you cannot do this through configuration. There might be other ways though..

0

精彩评论

暂无评论...
验证码 换一张
取 消