I've been fiddling with java.util.logging from jul-to-log4j bridge to the
idea of implementing a LogManager.
In the latter case there are a lot of deployability caveats, in particular
the fact that there is no common way of configuring them between servlet
containers. Trying to tame Websphere on this respect for instance  seems
like a difficult battle.
In the former case, the jul-to-log4j bridge suffers - in some environment -
from the fact that the LogManager & al may have security restrictions that
wont allow manipulating some Logger properties.
But in all cases, I miss the log4j deployability that does not require
anything but the fact that some classes exist in the jar/war (ie, no need to
set something globally in the servlet container or use a JVM wide property).

The only solution that I've been able to find is to have Solr cooperate and
implement its "own" org.apache.solr.Logger "shim" that behaves like a local
LogManager and trigger the implementation switch by using a log4j adapter
class; if the adapter class is present (aka loadable), the Loggers are
anonymous (j.u.l.Logger.getAnonymousLogger) with one handler that transforms
the LogRecord into log4j events. Otherwise, if that class is not present, it
just reverts to usual j.u.l logging. 
The only code change is to use org.apache.solr.logging.Logger.getLogger(...)
instead of java.util.logging.Logger.getLogger(...) (37 occurences if I'm not
mistaken). There are also 4 new files, only one being dependant on log4j and
one class whose presence in the jar/classpath determines the log4j
redirection.

In general terms, it means a "casual logging" library/application like Solr
can use JDK logging (and no external/log4j dependency) and be made log4j
"friendly" at a cost of 3 classes and a convention. I'm not sure this is a
valid bug/rfe to post and I don't know how to package this as a patch for
general consumption (log4j dependency, build.xml & al). Anyway, the "raw"
material is attached here for review & comments.
http://www.nabble.com/file/p16825364/logging.tar.gz logging.tar.gz 
Henri
-- 
View this message in context: 
http://www.nabble.com/logging-through-log4j-tp13747253p16825364.html
Sent from the Solr - Dev mailing list archive at Nabble.com.

Reply via email to