Search code examples
javalogginglog4jlog-level

LOG4J call only for specific function


asking this as an experiences Log4j user:

We have a pretty big class with lots of debug statements (Logger.getLogger(class).debug("Borrowed connection "+con.getId())... you know what I mean :)

Now I suspect one specific function to not work as expected and I want only this one particular function to log the debug output, the rest of the Class should keep the "error" level.

is there a solution to this? Google wouldn't satisfy my this time :)


Solution

  • You could use an own loger per method even though that may be a little inconvenient.

    Logger.getLogger(class.getName()+"#methodName").debug(..)
    

    will allow to define the log lever per method.