开发者

Logback - using appenders per method, rather then class

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" lev开发者_StackOverflowel="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.


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 :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜