I have a class with several methods. I would like each method to output to a different log file. With a logback.xml file like this, it logs ALL logging calls from the class.
<logger name="com.mincom.ellipse.conversion.BatchConverter" level="INFO">
<appender-ref ref="FILE" />
</logger>
How do I get per method logging calls. I'm sure it's very simple, but I cannot seem to see the answer in the doco.
What is an Appender? Logback delegates the task of writing a logging event to components called appenders. Appenders must implement the ch.qos.logback.core.Appender interface.
Logback natively implements the SLF4J API.
Log4J comes out the clear winner here, being able to write almost 270% more lines than JUL, 12.5% more than logback, 52% more than SLF4J SL.
Haven't used logback, but in log4j and others you can setup loggers with any name you like. Using the classes package and name is just a convention. So I'd setup Multiple loggers in your class, something like this:
Logger logA = LogFactory.getLogger("LogA");
Logger logB = LogFactory.getLogger("LogB");
public void methodA() {
logA.debug(...);
}
public void methodB() {
logB.debug(...);
}
And then in your logback setup ...
<logger name="LogA" level="INFO">
<appender-ref ref="FILE-A" />
</logger>
<logger name="LogB" level="INFO">
<appender-ref ref="FILE-B" />
</logger>
Should work. Probably needs some tweaking :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With