开发者

How to configure JDK logger formatting programatically?

开发者 https://www.devze.com 2023-03-13 19:51 出处:网络
How can I let my JDK logger use my customized formatter implementation without specifying a properties file? I want to set the format by programming.

How can I let my JDK logger use my customized formatter implementation without specifying a properties file? I want to set the format by programming.

for example I have my implementation like:

My Formatter e开发者_如何学JAVAxtends Formatter  {...}


Assuming that you have already built the Formatter implementation, you'll need to bind this to a Handler instance, so that the said handler will apply the formatter when logging the LogRecord objects (after all, that's how the Logging API was designed).

This is done by get a reference to the Handler instance of interest (you'll need to manage the creation of handlers in order to get a reference to them), and then invoking the setFormatter() method on it.

0

精彩评论

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

关注公众号