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 Jorge Medina <ce...@gmail.com> on 2011/01/18 20:31:19 UTC

Directing logging of a single class to a different file

Hello,

 I am trying to direct the output of a single class (MyClass)  to a
different log file.
 I added the following lines to my log4j configuration

###############################################################################
# Metrics Logger Appender
###############################################################################
log4j.logger.com.example.interceptor.MyClass=DEBUG, R2
log4j.appender.R2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R2.File=/some/path/metrics
log4j.appender.R2.DatePattern='-'yyyy-MM-dd'.log'
log4j.appender.R2.layout=org.apache.log4j.PatternLayout
log4j.appender.R2.layout.ConversionPattern=[%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ}]
[%X{username}] [%X{clientId}] %-5p %c{1} %m%n
log4j.additivity.com.example.interceptor.MyClass=false

###############################################################################
# Metrics Logger Package Selection
###############################################################################
log4j.logger.com.example.interceptor.MyClass=DEBUG

But I get the error messages:

log4j:WARN No appenders could be found for logger
(com.example.interceptor.MyClass).
log4j:WARN Please initialize the log4j system properly.

 Nevertheless it works when I remove the class name on the first line:

###############################################################################
# Metrics Logger Appender
###############################################################################
log4j.logger.com.example.interceptor=DEBUG, R2
log4j.appender.R2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R2.File=/some/path/metrics
log4j.appender.R2.DatePattern='-'yyyy-MM-dd'.log'
log4j.appender.R2.layout=org.apache.log4j.PatternLayout
log4j.appender.R2.layout.ConversionPattern=[%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ}]
[%X{username}] [%X{clientId}] %-5p %c{1} %m%n
log4j.additivity.com.example.interceptor.MyClass=false

###############################################################################
# Metrics Logger Package Selection
###############################################################################
log4j.logger.com.example.interceptor.MyClass=DEBUG


But this has the side effect of logging the output of other classes in
the same package (com.example.interceptor).
I really just want the log statements of a single class (MyClass).
I can't figure what I am doing wrong. Any help is appreciated.
Thanks

-Jorge

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


Re: Directing logging of a single class to a different file

Posted by Jorge Medina <ce...@gmail.com>.
Duh!

It was declared twice, the second was overriding the first declaration
not just (re)setting again the log level on the logger. Since the
second declaration has no appender, no files were being created.
Thank you!


On Tue, Jan 18, 2011 at 3:18 PM, Tim Watts <ti...@cliftonfarm.org> wrote:
> This may not be relevant but you have the logger for MyClass is declared
> twice. Try removing the 2nd one.
>
> On the other hand, it may be that log4j assumes the part after 'logger'
> is a package not a class? You could try using an xml config instead. But
> I would check the source code first (PropertiesConfigurator and
> Heirarchy or something like that -- been a while since I poked my nose
> in there). A lot of the code is remarkably straightforward.
>
>
> On Tue, 2011-01-18 at 14:31 -0500, Jorge Medina wrote:
>> Hello,
>>
>>  I am trying to direct the output of a single class (MyClass)  to a
>> different log file.
>>  I added the following lines to my log4j configuration
>>
>> ###############################################################################
>> # Metrics Logger Appender
>> ###############################################################################
>> log4j.logger.com.example.interceptor.MyClass=DEBUG, R2
>> log4j.appender.R2=org.apache.log4j.DailyRollingFileAppender
>> log4j.appender.R2.File=/some/path/metrics
>> log4j.appender.R2.DatePattern='-'yyyy-MM-dd'.log'
>> log4j.appender.R2.layout=org.apache.log4j.PatternLayout
>> log4j.appender.R2.layout.ConversionPattern=[%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ}]
>> [%X{username}] [%X{clientId}] %-5p %c{1} %m%n
>> log4j.additivity.com.example.interceptor.MyClass=false
>>
>> ###############################################################################
>> # Metrics Logger Package Selection
>> ###############################################################################
>> log4j.logger.com.example.interceptor.MyClass=DEBUG
>>
>> But I get the error messages:
>>
>> log4j:WARN No appenders could be found for logger
>> (com.example.interceptor.MyClass).
>> log4j:WARN Please initialize the log4j system properly.
>>
>>  Nevertheless it works when I remove the class name on the first line:
>>
>> ###############################################################################
>> # Metrics Logger Appender
>> ###############################################################################
>> log4j.logger.com.example.interceptor=DEBUG, R2
>> log4j.appender.R2=org.apache.log4j.DailyRollingFileAppender
>> log4j.appender.R2.File=/some/path/metrics
>> log4j.appender.R2.DatePattern='-'yyyy-MM-dd'.log'
>> log4j.appender.R2.layout=org.apache.log4j.PatternLayout
>> log4j.appender.R2.layout.ConversionPattern=[%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ}]
>> [%X{username}] [%X{clientId}] %-5p %c{1} %m%n
>> log4j.additivity.com.example.interceptor.MyClass=false
>>
>> ###############################################################################
>> # Metrics Logger Package Selection
>> ###############################################################################
>> log4j.logger.com.example.interceptor.MyClass=DEBUG
>>
>>
>> But this has the side effect of logging the output of other classes in
>> the same package (com.example.interceptor).
>> I really just want the log statements of a single class (MyClass).
>> I can't figure what I am doing wrong. Any help is appreciated.
>> Thanks
>>
>> -Jorge
>>
>> ---------------------------------------------------------------------
>> 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
>
>

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


Re: Directing logging of a single class to a different file

Posted by Tim Watts <ti...@cliftonfarm.org>.
This may not be relevant but you have the logger for MyClass is declared
twice. Try removing the 2nd one.

On the other hand, it may be that log4j assumes the part after 'logger'
is a package not a class? You could try using an xml config instead. But
I would check the source code first (PropertiesConfigurator and
Heirarchy or something like that -- been a while since I poked my nose
in there). A lot of the code is remarkably straightforward.


On Tue, 2011-01-18 at 14:31 -0500, Jorge Medina wrote:
> Hello,
> 
>  I am trying to direct the output of a single class (MyClass)  to a
> different log file.
>  I added the following lines to my log4j configuration
> 
> ###############################################################################
> # Metrics Logger Appender
> ###############################################################################
> log4j.logger.com.example.interceptor.MyClass=DEBUG, R2
> log4j.appender.R2=org.apache.log4j.DailyRollingFileAppender
> log4j.appender.R2.File=/some/path/metrics
> log4j.appender.R2.DatePattern='-'yyyy-MM-dd'.log'
> log4j.appender.R2.layout=org.apache.log4j.PatternLayout
> log4j.appender.R2.layout.ConversionPattern=[%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ}]
> [%X{username}] [%X{clientId}] %-5p %c{1} %m%n
> log4j.additivity.com.example.interceptor.MyClass=false
> 
> ###############################################################################
> # Metrics Logger Package Selection
> ###############################################################################
> log4j.logger.com.example.interceptor.MyClass=DEBUG
> 
> But I get the error messages:
> 
> log4j:WARN No appenders could be found for logger
> (com.example.interceptor.MyClass).
> log4j:WARN Please initialize the log4j system properly.
> 
>  Nevertheless it works when I remove the class name on the first line:
> 
> ###############################################################################
> # Metrics Logger Appender
> ###############################################################################
> log4j.logger.com.example.interceptor=DEBUG, R2
> log4j.appender.R2=org.apache.log4j.DailyRollingFileAppender
> log4j.appender.R2.File=/some/path/metrics
> log4j.appender.R2.DatePattern='-'yyyy-MM-dd'.log'
> log4j.appender.R2.layout=org.apache.log4j.PatternLayout
> log4j.appender.R2.layout.ConversionPattern=[%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ}]
> [%X{username}] [%X{clientId}] %-5p %c{1} %m%n
> log4j.additivity.com.example.interceptor.MyClass=false
> 
> ###############################################################################
> # Metrics Logger Package Selection
> ###############################################################################
> log4j.logger.com.example.interceptor.MyClass=DEBUG
> 
> 
> But this has the side effect of logging the output of other classes in
> the same package (com.example.interceptor).
> I really just want the log statements of a single class (MyClass).
> I can't figure what I am doing wrong. Any help is appreciated.
> Thanks
> 
> -Jorge
> 
> ---------------------------------------------------------------------
> 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: Directing logging of a single class to a different file

Posted by Jorge Medina <ce...@gmail.com>.
I really just want the log statements of a single class (MyClass) to
be directed to the new file. (set of files since I want to use the
daily rolling appender)
I can't figure what I am doing wrong. Any help is appreciated.

I am using log4j 1.2.13


On Tue, Jan 18, 2011 at 2:31 PM, Jorge Medina
<ce...@gmail.com> wrote:
> Hello,
>
>  I am trying to direct the output of a single class (MyClass)  to a
> different log file.
>  I added the following lines to my log4j configuration
>
> ###############################################################################
> # Metrics Logger Appender
> ###############################################################################
> log4j.logger.com.example.interceptor.MyClass=DEBUG, R2
> log4j.appender.R2=org.apache.log4j.DailyRollingFileAppender
> log4j.appender.R2.File=/some/path/metrics
> log4j.appender.R2.DatePattern='-'yyyy-MM-dd'.log'
> log4j.appender.R2.layout=org.apache.log4j.PatternLayout
> log4j.appender.R2.layout.ConversionPattern=[%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ}]
> [%X{username}] [%X{clientId}] %-5p %c{1} %m%n
> log4j.additivity.com.example.interceptor.MyClass=false
>
> ###############################################################################
> # Metrics Logger Package Selection
> ###############################################################################
> log4j.logger.com.example.interceptor.MyClass=DEBUG
>
> But I get the error messages:
>
> log4j:WARN No appenders could be found for logger
> (com.example.interceptor.MyClass).
> log4j:WARN Please initialize the log4j system properly.
>
>  Nevertheless it works when I remove the class name on the first line:
>
> ###############################################################################
> # Metrics Logger Appender
> ###############################################################################
> log4j.logger.com.example.interceptor=DEBUG, R2
> log4j.appender.R2=org.apache.log4j.DailyRollingFileAppender
> log4j.appender.R2.File=/some/path/metrics
> log4j.appender.R2.DatePattern='-'yyyy-MM-dd'.log'
> log4j.appender.R2.layout=org.apache.log4j.PatternLayout
> log4j.appender.R2.layout.ConversionPattern=[%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ}]
> [%X{username}] [%X{clientId}] %-5p %c{1} %m%n
> log4j.additivity.com.example.interceptor.MyClass=false
>
> ###############################################################################
> # Metrics Logger Package Selection
> ###############################################################################
> log4j.logger.com.example.interceptor.MyClass=DEBUG
>
>
> But this has the side effect of logging the output of other classes in
> the same package (com.example.interceptor).
> I really just want the log statements of a single class (MyClass).
> I can't figure what I am doing wrong. Any help is appreciated.
> Thanks
>
> -Jorge
>

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