[slf4j-user] New LogFactory stuff to select adapter

Simon Kitching skitching at apache.org
Wed May 25 14:29:43 CEST 2005


Hi Ceki,

I see code has recently been added to LogFactory to use system
properties to determine the adapter class to use. If no such property is
set, then default to the statically bound class.

Unfortunately, I don't see the point of this.

System properties are global across all components in a container (eg
webapps). There is no ability to set different system properties per
container. So this would force the same adapter to be used across all
components, yes?

JCL tries to solve this issue by avoiding system properties and instead
looking for a file "commons-logging.properties" in the context classpath
(or META-INF/services/org.apache.commons.logging.LogFactory) and using
an entry from that to specify the adapter class to use. This
does provide the per-component configurability that is really needed.
Unfortunately that approach carries a fair bit of complexity with it:
  * need to access context classloader
  * accessing context classloader can trigger security exceptions, so
    need to do it within an AccessController
  * need to read the file found and extract a key entry
  * need to handle case where child classloader is parent-first and
    the parent has a config file with the same name. JCL1.0.4 doesn't
    actually handle this correctly, but the upcoming release should.

I don't know what the "right" solution is, but I don't see system
properties as being appropriate for selecting the adapter class in a
container that may have multiple components.

Regards,

Simon





More information about the slf4j-user mailing list