You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Jeff Sawatzky <je...@locationary.com> on 2012/06/07 00:26:51 UTC

slf4j, log4j and PropertyConfigurator.configure

I have a project where I am using slf4j with the log4j binder, and I am trying to configure log4j with the PropertyConfigurator.  The project allows for a common log4.properties file and a machine log4j.properties file, and at start up I load the two files, combine them into a Properties object, and then pass them to PropertyConfigurator.configure. But when I try to log using slf4j I get a "log4j:WARN No appenders could be found for logger" error on the class I am trying to log from.

In my app startup I have..

Properties props = //do work.......
LogManager.resetConfiguration();
PropertyConfigurator.configure(props);

but here is the output (with log4j.debug turned on)
log4j: Parsing for [root] with value=[INFO, stdout].
log4j: Level token is [INFO].
log4j: Category root set to INFO
log4j: Parsing appender named "stdout".
log4j: Parsing layout options for "stdout".
log4j: Setting property [conversionPattern] to [%-4r [%t] %-5p %c %x - %m%n].
log4j: End of parsing for "stdout".
log4j: Parsed "stdout" options.
log4j: Finished configuring.
log4j: Parsing for [root] with value=[INFO].
log4j: Level token is [INFO].
log4j: Category root set to INFO
log4j: Finished configuring.
log4j:WARN No appenders could be found for logger (com.loca.util.services.AppListener).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

Shouldn't the logger for com.loca.util.services.AppListener use the root appender that was configured?

Thanks!

Re: slf4j, log4j and PropertyConfigurator.configure

Posted by Jacob Kjome <ho...@visi.com>.
Do you have multiple copies of log4j.jar in different classloaders?  For 
instance, let's say you run under Tomcat where webapps use child-first 
classloading.  You place log4j and slf4j in WEB-INF/lib and configure Log4j 
for this classloader.  But then you also have log4j/slf4j in a parent 
classloader which didn't get configured and the code performing logging is 
also part of the parent classloader, not the webapp classloader.  In this 
case, the "no appenders could be found" message makes sense.

I'm not saying the above is exactly your situation, but possibly some 
derivation of it.

Jake

On Wed, 6 Jun 2012 18:26:51 -0400
 Jeff Sawatzky <je...@locationary.com> wrote:
> I have a project where I am using slf4j with the log4j binder, and I am 
>trying to configure log4j with the PropertyConfigurator.  The project allows 
>for a common log4.properties file and a machine log4j.properties file, and at 
>start up I load the two files, combine them into a Properties object, and 
>then pass them to PropertyConfigurator.configure. But when I try to log using 
>slf4j I get a "log4j:WARN No appenders could be found for logger" error on 
>the class I am trying to log from.
> 
> In my app startup I have..
> 
> Properties props = //do work.......
> LogManager.resetConfiguration();
> PropertyConfigurator.configure(props);
> 
> but here is the output (with log4j.debug turned on)
> log4j: Parsing for [root] with value=[INFO, stdout].
> log4j: Level token is [INFO].
> log4j: Category root set to INFO
> log4j: Parsing appender named "stdout".
> log4j: Parsing layout options for "stdout".
> log4j: Setting property [conversionPattern] to [%-4r [%t] %-5p %c %x - 
>%m%n].
> log4j: End of parsing for "stdout".
> log4j: Parsed "stdout" options.
> log4j: Finished configuring.
> log4j: Parsing for [root] with value=[INFO].
> log4j: Level token is [INFO].
> log4j: Category root set to INFO
> log4j: Finished configuring.
> log4j:WARN No appenders could be found for logger 
>(com.loca.util.services.AppListener).
> log4j:WARN Please initialize the log4j system properly.
> log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for 
>more info.
> 
> Shouldn't the logger for com.loca.util.services.AppListener use the root 
>appender that was configured?
> 
> Thanks!


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: slf4j, log4j and PropertyConfigurator.configure

Posted by Jeff Sawatzky <je...@locationary.com>.
Ah, good catch!

log4j was being automatically initialized once from the log4j.properties in the war. Then, when I load the multiple property files and combine them (which I use commons configuration to do) it was converting the "INFO, stdout" from a string to an array.

I've now escaped the "," in my properties file and it seems to work fine now.

Thanks again!

Jeff.

On 2012-06-07, at 4:26 AM, ceki wrote:

> Hello Jeff,
> 
> From the messages log4j outputs at configuration time, it very much
> looks like the root logger is defined twice with the second definition
> with no appender. Hence the "log4j:WARN No appenders could be found
> for logger (com.loca.util.services.AppListener)" message.
> 
> HTH,
> -- 
> Ceki
> http://twitter.com/#!/ceki
> 
> On 07.06.2012 00:26, Jeff Sawatzky wrote:
> 
> > I have a project where I am using slf4j with the log4j binder, and I
> > am trying to configure log4j with the PropertyConfigurator.  The
> > project allows for a common log4.properties file and a machine
> > log4j.properties file, and at start up I load the two files, combine
> > them into a Properties object, and then pass them to
> > PropertyConfigurator.configure. But when I try to log using slf4j I
> > get a "log4j:WARN No appenders could be found for logger" error on the
> > class I am trying to log from.
>> 
>> In my app startup I have..
>> 
>> Properties props = //do work.......
>> LogManager.resetConfiguration();
>> PropertyConfigurator.configure(props);
>> 
>> but here is the output (with log4j.debug turned on)
>> log4j: Parsing for [root] with value=[INFO, stdout].
>> log4j: Level token is [INFO].
>> log4j: Category root set to INFO
>> log4j: Parsing appender named "stdout".
>> log4j: Parsing layout options for "stdout".
>> log4j: Setting property [conversionPattern] to [%-4r [%t] %-5p %c %x - %m%n].
>> log4j: End of parsing for "stdout".
>> log4j: Parsed "stdout" options.
>> log4j: Finished configuring.
>> log4j: Parsing for [root] with value=[INFO].
>> log4j: Level token is [INFO].
>> log4j: Category root set to INFO
>> log4j: Finished configuring.
>> log4j:WARN No appenders could be found for logger (com.loca.util.services.AppListener).
>> log4j:WARN Please initialize the log4j system properly.
>> log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
>> 
>> Shouldn't the logger for com.loca.util.services.AppListener use the root appender that was configured?
>> 
>> Thanks!
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: slf4j, log4j and PropertyConfigurator.configure

Posted by ceki <ce...@qos.ch>.
Hello Jeff,

 From the messages log4j outputs at configuration time, it very much
looks like the root logger is defined twice with the second definition
with no appender. Hence the "log4j:WARN No appenders could be found
for logger (com.loca.util.services.AppListener)" message.

HTH,
-- 
Ceki
http://twitter.com/#!/ceki

On 07.06.2012 00:26, Jeff Sawatzky wrote:

 > I have a project where I am using slf4j with the log4j binder, and I
 > am trying to configure log4j with the PropertyConfigurator.  The
 > project allows for a common log4.properties file and a machine
 > log4j.properties file, and at start up I load the two files, combine
 > them into a Properties object, and then pass them to
 > PropertyConfigurator.configure. But when I try to log using slf4j I
 > get a "log4j:WARN No appenders could be found for logger" error on the
 > class I am trying to log from.
>
> In my app startup I have..
>
> Properties props = //do work.......
> LogManager.resetConfiguration();
> PropertyConfigurator.configure(props);
>
> but here is the output (with log4j.debug turned on)
> log4j: Parsing for [root] with value=[INFO, stdout].
> log4j: Level token is [INFO].
> log4j: Category root set to INFO
> log4j: Parsing appender named "stdout".
> log4j: Parsing layout options for "stdout".
> log4j: Setting property [conversionPattern] to [%-4r [%t] %-5p %c %x - %m%n].
> log4j: End of parsing for "stdout".
> log4j: Parsed "stdout" options.
> log4j: Finished configuring.
> log4j: Parsing for [root] with value=[INFO].
> log4j: Level token is [INFO].
> log4j: Category root set to INFO
> log4j: Finished configuring.
> log4j:WARN No appenders could be found for logger (com.loca.util.services.AppListener).
> log4j:WARN Please initialize the log4j system properly.
> log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
>
> Shouldn't the logger for com.loca.util.services.AppListener use the root appender that was configured?
>
> Thanks!


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org