[slf4j-user] Multi-step configuration

Ceki Gülcü ceki at qos.ch
Fri Oct 7 09:20:54 CEST 2011


Hi David,

I've looked at the source code for com.mchange.v2.log.MLog and could not 
find any direct support for SLF4J. I presume you have installed 
log4j-over-slf4j on your class path. Right?

Coming back to your question, the link [1] mentioned in the warning 
output by SLF4J provides an explanation for the problem.

Here is the gist of it:

   The only way to obtain output from the listed loggers, is to
   isolate the components invoking these loggers and to exclude
   them from the default configuration. Both logback and log4j allow
   multi-step configuration. It follows that the problematic components
   should be configured in a second step separate from default
   configuration.

Thus, you remove the part that configures  DBAppender from the 
default/initial configuration file and place it in another file, say 
logback-secondary.xml. You then load this secondary configuration file 
as follows:

  LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
  try {
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);
    // don't reset the existing configuration
    // lc.reset();
    configurator.doConfigure(path to logback-secondary.xml);
  } catch (JoranException je) {
    // StatusPrinter will handle this
  }
  StatusPrinter.printInCaseOfErrorsOrWarnings(lc);

See also [2] on invoking JoranConfigurator directly.

I hope this helps,

[1] http://www.slf4j.org/codes.html#substituteLogger
[2] http://logback.qos.ch/manual/configuration.html#joranDirectly

-- 
http://twitter.com/ceki

On 06/10/2011 11:16 PM, David Felsenthal wrote:
> I have read the FAQ and looked on the net and banged my head into this.
> My configuration file is:
>
> <configuration scan="true" debug="true">
>
> 	<appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
> 		<connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
> 			<dataSource class="com.mchange.v2.c3p0.ComboPooledDataSource">
> 				<driverClass>org.postgresql.Driver</driverClass>
> 				<jdbcUrl>jdbc:postgresql://dfelsenthal-pc2/testdb_david</jdbcUrl>
> 				<user>user</user>
> 				<password>password</password>
> 			</dataSource>
> 		</connectionSource>
> 	</appender>
>
>
> 	<logger name="com.mchange.v2" level="OFF" />
> 	<logger name="org.hibernate" level="WARN" />
>
> 	<root level="INFO">
> 		<appender-ref ref="DB" />
> 	</root>
> </configuration>
>
> and I am getting the usual
>
> SLF4J: The following loggers will not work becasue they were created
> SLF4J: during the default configuration phase of the underlying logging system.
> SLF4J: See also http://www.slf4j.org/codes.html#substituteLogger
> SLF4J: com.mchange.v2.log.MLog
> .....
>
> Can anyone suggest how to set up the multi-step for the c3p0 classes?
> I can't quite figure it out.
>
> Thanks in advance,
> David
>
>



More information about the slf4j-user mailing list