Search code examples
logginglog4japache-commons-logging

Redirecting logs from component using commons logging through application log4j.xml


I am new to logging mechanisms , hence pardon me if my question seems naive.

I am using log4j in my web application, but one of the components used uses a customer logger, say A that implements org.apache.commons.logging.Log. I want to redirect the all the logs from A to a separate log file and am facing issues when I try to declare a custom appender and redirect logs from A in the log4j.xml.

How should I go about doing this? Please help.


Solution

  • I think you can use slf4j for this. These library has bridges for legacy logging frameworks: http://www.slf4j.org/legacy.html and slf4j has implementation for different underlying logging frameworks. I never tried this but it should work:

    commonslogging -> slf4j -> log4j