Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to implement a Custom logger which logs all log entries to a Database. Currently my app logs this way (slf4j and log4j binding):

private static final Logger logger = LoggerFactory.getLogger( MyClass.class );

I'm not sure how to proceed. My Idea is to implement a Custom Logging binding through implementing the org.slf4j.Logger Interface

What would be the next steps? My target is to not change the current code

Links I considered:

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
840 views
Welcome To Ask or Share your Answers For Others

1 Answer

it should be fairly easy. you'll need to implement your own Logger and LoggerFactory. you will not have to change existing code at all.

after doing that you'll need to implement StaticLoggerBinder to return your logger factory and class name. if you download the slf4j zip file then you get the source for all the implementations too, just have a look at the StaticLoggerBinder in slf4j-log4j for an example.

have a look at this link for details : http://www.slf4j.org/faq.html#slf4j_compatible


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...