[slf4j-user] Multi-step configuration

David Felsenthal dfelsenthal at batterymarch.com
Fri Oct 7 15:25:13 CEST 2011


Thanks. I am all set now.

I do have log4j-over-slf4j on the classpath.

For me the difficulty was in realizing that the multiple steps were handled by application code, rather than some subtle trigger in the logging configuration file itself. That was my conceptual error.

One small suggestion, though. I did rear, re-read and re-re-read the paragraph pointed to by the very helpful error message. I understood the bootstrapping issues. Perhaps in the note that points out the possibility of multi-step configuration you could mention that any subsequent configuration steps need to be initiated or carried out by the application itself.

Thanks again, and I really like the DBAppender.



-----Original Message-----
From: slf4j-user-bounces at qos.ch [mailto:slf4j-user-bounces at qos.ch] On Behalf Of Ceki Gülcü
Sent: Friday, October 07, 2011 3:21 AM
To: User list for the slf4j project
Subject: Re: [slf4j-user] Multi-step configuration

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
>
>

_______________________________________________
slf4j-user mailing list
slf4j-user at qos.ch
http://qos.ch/mailman/listinfo/slf4j-user

This message is intended for the addressee only and may contain privileged or confidential information. Unless you are the intended recipient, you may not use, copy or disclose to anyone any information contained in this message. If you have received this message in error, please notify the author by replying to this message and then kindly delete the message. Thank you.


More information about the slf4j-user mailing list