tags:

views:

287

answers:

1

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:

http://stackoverflow.com/questions/1770442/java-custom-logger-logging-standards-or-and-best-practices http://www.slf4j.org/manual.html

A: 

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

oedo
Thanks oedo!Is it also possible to use log4j in my logging framework, e.g. to only write errors and warning to the Database and use log4j for the rest?The problem is that I have 2 bindings than http://www.slf4j.org/codes.html#multiple_bindings
Martin Dürrmeier
at the moment it seems a custom log4j appender is what i'm looking for so warn error and warning level goes to my custom appender while the rest remains at it is (configured in log4j.xml)
Martin Dürrmeier
sure, i guess you could write your custom logger so that it forwards the relevant requests to log4j. again, have a look at the source for slf4j-log4j to get you started :)
oedo