Backup - using applications for each method, not a class

I have a class with several methods. I would like each method to output to a different log file. With such a logback.xml file, 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 calls to log a method. I am sure this is very simple, but I cannot see the answer in doco.

+4
source share
1 answer

Did not use logback, but in log4j and others you can configure loggers with any name that you like. Using the class package and name is just a convention. Therefore, I would install several logisticians 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 setting up your log ...

 <logger name="LogA" level="INFO"> <appender-ref ref="FILE-A" /> </logger> <logger name="LogB" level="INFO"> <appender-ref ref="FILE-B" /> </logger> 

Must work. Some setup is probably required :-)

+4
source

All Articles