how to deal with logging in production code (logback/slf4j) -


i've implemented algorithmic framework consisting of several classes. logging, use slf4j , logback. many of classes have code like:

protected final logger logger = loggerfactory.getlogger(myclass.class); ... logger.debug("some debug information"); 

now package code , make production ready. do logging code?

  1. when running code, developer typically want turn off logging performance reasons.
  2. while developing code debug information helpful removing debug statements bad idea.

so ideally users should able enable/disable logging. have logback.xml configuration file specifies log level on per-class basis. should include such file in package? or should expect users write own or supply default configuration file?

i have code configure algorithms:

/** * read algorithm confirguration properties file **/     protected configuration(properties properties){...} 

this function reads properties file , sets number of algorithmic parameters accordingly. of use enable/disable logging various classes?

slf4j , logback have little performance impact if logging level turned off. i've never come across problem leaving logging code in. has added benefit of being able turn on debug logging in production environment more information sporadically happening problem.

since create loggers classes, can configure loggers not have appender if not want logging output framework. or set level value comfortable in productive environment - remember turn off additivity, events aren't propagated root logger. syntax described here: http://logback.qos.ch/manual/configuration.html#syntax

another simple idea enable user turn off logging framework easy switch use marker appropriate filter. can change logging calls start marker:

private marker my_marker = markerfactory.getmarker("frameworkmarker");  logger.debug(my_marker, "some debug information"); 

that allows suppress logging output marked specific marker single turbofilter defined in application's logback.xml:

http://logback.qos.ch/manual/filters.html#turbofilter

<turbofilter class="ch.qos.logback.classic.turbo.markerfilter">     <marker>frameworkmarker</marker>     <onmatch>deny</onmatch> </turbofilter> 

the markerfilter has added benefit of not caring level. logging event specified marker filtered out (and in efficient way, described in documentation).

personally, go both. way can use logging levels in framework , deactivate logging via markerfilter if needed, can reap benefits of detailed , level-specific logging when need it.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -