Customizing log format in logging.properties

左心房为你撑大大i 提交于 2019-12-05 10:06:57

If you are using Java 7 (or later :-)) you no longer have to create a custom formatter class for java.util.logging (JUL). In Java 7 there's a new property, java.util.logging.SimpleFormatter.format, which controls how JUL's SimpleFormatter prints the information. So as long as you are using SimpleFormatter (which is the default anyway) then this will work.

Some pitfalls:

  • Be sure to actually use Java 7. :-)
  • Be sure to use a valid format string. JUL will revert silently to the default format (the standard ugly two-liner) if the format you provide is invalid.

It looks like you would do this by creating a custom class that extends Formatter and then specify it in your logging.properties as the formatter for your handler. For example, if you are using a ConsoleHandler you would use this:

java.util.logging.ConsoleHandler.formatter = com.mycompany.MyFormatter

Then place the class file (either by itself, or inside a jar) somewhere in the classpath of tomcat. I would create a jar with it in there and then put that jar in ${catalina.home}/lib/ext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!