开发者

Using java.util.Formatter as default formatter for slf4j

开发者 https://www.devze.com 2023-02-19 19:43 出处:网络
I currently have a custom log manager that internally uses java.util.Formatter. The main issue is that it\'s not very usable: everything in one file per application, no possibilities to add specific l

I currently have a custom log manager that internally uses java.util.Formatter. The main issue is that it's not very usable: everything in one file per application, no possibilities to add specific logs in a database, not able to send a mail, ...

So I would like to be able to increase the capabilities our logging system. After a few tests, Log4J is exactly what I need right now. But I would like to avoid the pain to re-change this again in the future, so I plan to use slf4j on top of Log4J.

Even if I'm ready to make a big search/replace in all my codebase to u开发者_运维技巧se slf4j, I'm not ready to check each log statement and reformat it to use the {} format of slf4j.

So my question is: how can I use slf4j interface and tell it that internally it should use a java.util.Formatter instead of its default one, preferably in one place (meaning not in each class or package)?

Notes: all answers speaking about performances or stating that I shouldn't use j.u.Formatter will be discarded: I need a pragmatic solution to my problem, not launching a debate.


There is patch http://bugzilla.slf4j.org/show_bug.cgi?id=116 which can be modified to suit your needs. The discussion present there can also give further clarity on using util.Formatter.

0

精彩评论

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

关注公众号