As everyone is probably aware, CXF uses the j.u.l API for all of it's logging.
That's really not likely to change, but we do allow logging to Log4J by
setting some system properties or a file in META-INF/cxf.
However, I was thinking it might make sense to try and detect where SLF4J is
logging and if it's logging to Log4J, we should as well. The reflection
code to do that isn't very complex:
Class.forName("org/slf4j/impl/StaticLoggerBinder");
Class<?> cls = Class.forName("org.slf4j.LoggerFactory");
Class<?> fcls = cls.getMethod("getILoggerFactory").invoke(null).getClass();
if (fcls.getName().contains("Log4j")) {
cname = "org.apache.cxf.common.logging.Log4jLogger";
} else if (fcls.getName().contains("JCL")) {
cls = Class.forName("org.apache.commons.logging.LogFactory");
fcls = cls.getMethod("getFactory").invoke(null).getClass();
if (fcls.getName().contains("Log4j")) {
cname = "org.apache.cxf.common.logging.Log4jLogger";
}
}
What are peoples thoughts on doing that? That way, if SLF4J is logging to
Log4J, or if SLF4J is logging to JCL which is logging to Log4J, we would log
to Log4J as well. If SLF4J is logging to someplace else, we'd still log to
j.u.l so that wouldn't change.
One note: with PAX logging in servicemix/felix, the ILoggerFactory would not
contain "Log4j". Thus, we'd continue to use j.u.l. But that is OK as PAX
logging already interceptor j.u.l and directs them to the same place.
Thoughts? Comments?
--
Daniel Kulp
[email protected]
http://www.dankulp.com/blog