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 aggarwal <ak...@gmail.com> on 2012/06/07 10:51:07 UTC

class specific logging level

Hi,

Is it possible to set logging level for few selected classes in appender to
DEBUG and rest all ERROR ? Is there any combination of filter that can do
this ?
-- 
View this message in context: http://old.nabble.com/class-specific-logging-level-tp33974515p33974515.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: class specific logging level

Posted by Jacob Kjome <ho...@visi.com>.
How do you define your logger in your Java code?  I'm suspicious that the 
logger name you've defined as "MyClass" is merely the simple name of the 
class, not the fully qualified name of the class that you've likely defined it 
for your logger name.

That is, if "MyClass" is in the package "com.mypackage", and you've defined 
the logger using something like...

Logger logger = Logger.getLogger(MyClass.class);
OR
Logger logger = Logger.getLogger(MyClass.class.getName());

...then your configuration should be....

<logger name="com.mypackage.MyClass">
 <level value="DEBUG" />
</logger>

Note that "additivity" is "true" by default and need only be specified if you 
want to set it to "false" (which would mean you wouldn't inherit 
appenders/levels from ancestor loggers).

Also note that "priority" is the deprecated name for "level".  It will work 
the same, but you should just use "level" to avoid confusion.

Finally, you mention you want all other classes to log at the ERROR level, yet 
you defined the level in "root" as INFO.  Typo?


Jake

On Fri, 8 Jun 2012 08:45:21 -0700 (PDT)
 aggarwal <ak...@gmail.com> wrote:
> 
> Hi,
> 
> I have tried it with the following configuration :
> 
> 
> <appender name="Log1" class="org.apache.log4j.RollingFileAppender">
> 	
> 	
> 	
>        
> 	
>        <layout class="org.apache.log4j.PatternLayout">
> 	              
> 	</layout>
> </appender>
> 
> <logger name="MyClass" additivity="true">
> 	<level value="DEBUG" />
> </logger>
> 
> <root>
> 	<priority value="INFO" />
> 	<appender-ref ref="Log1" />
> </root>
> 
> 
> I want MyClass logs of DEBUG level and all other classes of ERROR in
> "log1.log" file as mentioned in logger "Log1". But it isnt happening. Am not
> getting any DEBUG logs in "log1.log" whereas if I set the level in appender
> "Log1" to DEBUG, I do get the DEBUG logs of Myclass in log1.log. I am sorry
> if am still making some mistake here. Please correct me where am I wrong.
> 
> Thanks for such quick replies.
> 
> 
> 
> 
> 
> Jacob Kjome wrote:
>> 
>> 
>> What I've provided does exactly what you are asking for.  Setting your
>> class 
>> logging level to DEBUG overrides the inherited level from root for the 
>> specified logger name.  Why don't you just try it and see what it does
>> rather 
>> than speculate on why you believe it wouldn't work?  You can also read try 
>> reading the docs...
>> 
>> http://logging.apache.org/log4j/1.2/manual.html
>> 
>> Jake
>> 
>> On Thu, 7 Jun 2012 20:44:05 -0700 (PDT)
>>  aggarwal <ak...@gmail.com> wrote:
>>> 
>>> So when root level is ERROR and i set Myclass level to DEBUG, how will
>>> the
>>> Myclass's DEBUG logs get logged since the root level is ERROR and it will
>>> block the DEBUG logs ? What i know is that, if I set root level to DEBUG
>>> and
>>> some particular class (say Myclass) logger level to ERROR then, all
>>> classes'
>>> logs of DEBUG will get logged but not of Myclass as its restricted to
>>> ERROR.
>>> But what I want is the vice-versa. I want ERROR level of all classes and
>>> DEBUG of only few important classes. I am new to log4j so maybe what i am
>>> sayin is wrong.
>>> 
>>> 
>>> 
>>> Jacob Kjome wrote:
>>>> 
>>>> 
>>>> If you name your loggers by class name, then sure.  This is standard
>>>> logging 
>>>> configuration, not some extra special workaround.
>>>> 
>>>> <logger name="com.mypackage.Myclass">
>>>>     <level value="debug"/>
>>>>     <!-- inherits A1 appender from root, applies only to
>>>> com.mypackage.MyClass 
>>>> -->
>>>> </logger>
>>>> <logger name="com.myotherpackage">
>>>>     <level value="debug"/>
>>>>     <!-- inherits A1 appender from root, applies to all classes in 
>>>> "com.myotherpackage" -->
>>>> </logger>
>>>> <root>
>>>>     <level value="error"/>
>>>>     <appender-ref ref="A1"/>
>>>> </root>
>>>> 
>>>> 
>>>> Jake
>>>> 
>>>> On Thu, 7 Jun 2012 01:51:07 -0700 (PDT)
>>>>  aggarwal <ak...@gmail.com> wrote:
>>>>> 
>>>>> Hi,
>>>>> 
>>>>> Is it possible to set logging level for few selected classes in
>>>>> appender
>>>>> to
>>>>> DEBUG and rest all ERROR ? Is there any combination of filter that can
>>>>> do
>>>>> this ?
>>>>> -- 
>>>>> View this message in context: 
>>>>>http://old.nabble.com/class-specific-logging-level-tp33974515p33974515.html
>>>>> Sent from the Log4j - Users mailing list archive at Nabble.com.
>>>>> 
>>>>> 
>>>>> ---------------------------------------------------------------------
>>>>> 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
>>>> 
>>>> 
>>>> 
>>> 
>>> -- 
>>> View this message in context: 
>>>http://old.nabble.com/class-specific-logging-level-tp33974515p33979415.html
>>> Sent from the Log4j - Users mailing list archive at Nabble.com.
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> 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
>> 
>> 
>> 
> 
> -- 
> View this message in context: 
>http://old.nabble.com/class-specific-logging-level-tp33974515p33982398.html
> Sent from the Log4j - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> 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: class specific logging level

Posted by aggarwal <ak...@gmail.com>.
I will try setting root level to ERROR. All the other config is as u
suggested. Will try to debug why MyClass DEBUG logs arent getting logged
when its logger level is DEBUG. Thanks for detailed description.



Jacob Kjome wrote:
> 
> 
> First, you are not setting the level of the appender, but that of the
> logger 
> which can reference any given appender, including your named "Log1"
> appender.  
> So, if you want ERROR level for all classes, then set the "root" logger
> level 
> to ERROR. 
> 
> After that, you make a decision of which appenders you want logging to go
> to 
> (disregarding level, as that is the job of the logger - except in regard
> to 
> more advanced configuration where you can set appender level thresholds or
> use 
> filters, but that's beyond our discussion here).  If you want output of
> all 
> classes (again, disregarding level) to go to the "Log1", then you provide
> a 
> reference to "Log1" in the primordial "root" logger.
> 
> After that, if you want to lower the level for specific loggers, you can 
> specify those as you've done with "com.pkg.MyClass".  Now all classes, 
> including "com.pkg.MyClass" will log at the ERROR level, but
> "com.pkg.MyClass" 
> will also provide DEBUG, INFO, and WARN (and SEVERE) logging as well.
> 
> This is all very standard stuff.  If you don't experience the above
> behavior, 
> then I would suspect that the Log4j configuration you think you are using 
> isn't being used at all.  You might want to use...
> 
> -Dlog4j.debug=true
> 
> This will tell Log4j to report how it is being configured.  You may find
> that 
> some other configuration is being used instead of yours.  Either that, or
> you 
> are not describing what you want clearly enough.
> 
> 
> Jake
> 
> On Fri, 8 Jun 2012 09:15:14 -0700 (PDT)
>  aggarwal <ak...@gmail.com> wrote:
>> 
>> 
>> If I set the level of Log1 appender to DEBUG, then DEBUG logs of all the
>> classes including MyClass are getting logged. If I set it to ERROR, then
>> ERROR logs of all the classes including MyClass are getting logged. But
>> what
>> I want is - DEBUG logs of only MyClass and ERROR of rest all. Here, my
>> motive is to set DEBUG level logging for most important classes helping
>> in
>> debugging procedure. 
>> 
>> 
>> <logger name="com.pkg.MyClass">
>> 	<level value="DEBUG" />
>> </logger>
>> 
>> private final static Logger logger = Logger.getLogger(MyClass.class);
>> 
>> This is how a logger is defined in my code. It was my mistake to replace
>> "com.pkg.MyClass" with "MyClass". 
>> 
>> Thanks for "additivity" and "priority" related suggestions.
>> 
>> Actually, root isn't my concern here. No matter what the level of root
>> and
>> appender is, I want DEBUG logs of only MyClass.
>> 
>> 
>> 
>> 
>> 
>> Douglas E Wegscheid wrote:
>>> 
>>>> I want MyClass logs of DEBUG level and all other classes of ERROR in
>>>> "log1.log" file as mentioned in logger "Log1". 
>>>> ...
>>>> whereas if I set the level in appender
>>>> "Log1" to DEBUG, I do get the DEBUG logs of Myclass in log1.log.
>>> 
>>> If you set the level of the Log1 appender to DEBUG, you say that you get 
>>> the DEBUG logs of Myclass in log1.log. Isn't that what you want?
>>> 
>> 
>> -- 
>> View this message in context: 
>>http://old.nabble.com/class-specific-logging-level-tp33974515p33982558.html
>> Sent from the Log4j - Users mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> 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
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/class-specific-logging-level-tp33974515p33982872.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: class specific logging level

Posted by Jacob Kjome <ho...@visi.com>.
First, you are not setting the level of the appender, but that of the logger 
which can reference any given appender, including your named "Log1" appender.  
So, if you want ERROR level for all classes, then set the "root" logger level 
to ERROR. 

After that, you make a decision of which appenders you want logging to go to 
(disregarding level, as that is the job of the logger - except in regard to 
more advanced configuration where you can set appender level thresholds or use 
filters, but that's beyond our discussion here).  If you want output of all 
classes (again, disregarding level) to go to the "Log1", then you provide a 
reference to "Log1" in the primordial "root" logger.

After that, if you want to lower the level for specific loggers, you can 
specify those as you've done with "com.pkg.MyClass".  Now all classes, 
including "com.pkg.MyClass" will log at the ERROR level, but "com.pkg.MyClass" 
will also provide DEBUG, INFO, and WARN (and SEVERE) logging as well.

This is all very standard stuff.  If you don't experience the above behavior, 
then I would suspect that the Log4j configuration you think you are using 
isn't being used at all.  You might want to use...

-Dlog4j.debug=true

This will tell Log4j to report how it is being configured.  You may find that 
some other configuration is being used instead of yours.  Either that, or you 
are not describing what you want clearly enough.


Jake

On Fri, 8 Jun 2012 09:15:14 -0700 (PDT)
 aggarwal <ak...@gmail.com> wrote:
> 
> 
> If I set the level of Log1 appender to DEBUG, then DEBUG logs of all the
> classes including MyClass are getting logged. If I set it to ERROR, then
> ERROR logs of all the classes including MyClass are getting logged. But what
> I want is - DEBUG logs of only MyClass and ERROR of rest all. Here, my
> motive is to set DEBUG level logging for most important classes helping in
> debugging procedure. 
> 
> 
> <logger name="com.pkg.MyClass">
> 	<level value="DEBUG" />
> </logger>
> 
> private final static Logger logger = Logger.getLogger(MyClass.class);
> 
> This is how a logger is defined in my code. It was my mistake to replace
> "com.pkg.MyClass" with "MyClass". 
> 
> Thanks for "additivity" and "priority" related suggestions.
> 
> Actually, root isn't my concern here. No matter what the level of root and
> appender is, I want DEBUG logs of only MyClass.
> 
> 
> 
> 
> 
> Douglas E Wegscheid wrote:
>> 
>>> I want MyClass logs of DEBUG level and all other classes of ERROR in
>>> "log1.log" file as mentioned in logger "Log1". 
>>> ...
>>> whereas if I set the level in appender
>>> "Log1" to DEBUG, I do get the DEBUG logs of Myclass in log1.log.
>> 
>> If you set the level of the Log1 appender to DEBUG, you say that you get 
>> the DEBUG logs of Myclass in log1.log. Isn't that what you want?
>> 
> 
> -- 
> View this message in context: 
>http://old.nabble.com/class-specific-logging-level-tp33974515p33982558.html
> Sent from the Log4j - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> 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: class specific logging level

Posted by aggarwal <ak...@gmail.com>.

If I set the level of Log1 appender to DEBUG, then DEBUG logs of all the
classes including MyClass are getting logged. If I set it to ERROR, then
ERROR logs of all the classes including MyClass are getting logged. But what
I want is - DEBUG logs of only MyClass and ERROR of rest all. Here, my
motive is to set DEBUG level logging for most important classes helping in
debugging procedure. 


<logger name="com.pkg.MyClass">
	<level value="DEBUG" />
</logger>

private final static Logger logger = Logger.getLogger(MyClass.class);

This is how a logger is defined in my code. It was my mistake to replace
"com.pkg.MyClass" with "MyClass". 

Thanks for "additivity" and "priority" related suggestions.

Actually, root isn't my concern here. No matter what the level of root and
appender is, I want DEBUG logs of only MyClass.





Douglas E Wegscheid wrote:
> 
>> I want MyClass logs of DEBUG level and all other classes of ERROR in
>> "log1.log" file as mentioned in logger "Log1". 
>> ...
>> whereas if I set the level in appender
>> "Log1" to DEBUG, I do get the DEBUG logs of Myclass in log1.log.
> 
> If you set the level of the Log1 appender to DEBUG, you say that you get 
> the DEBUG logs of Myclass in log1.log. Isn't that what you want?
> 

-- 
View this message in context: http://old.nabble.com/class-specific-logging-level-tp33974515p33982558.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: class specific logging level

Posted by Douglas E Wegscheid <Do...@whirlpool.com>.
> I want MyClass logs of DEBUG level and all other classes of ERROR in
> "log1.log" file as mentioned in logger "Log1". 
> ...
> whereas if I set the level in appender
> "Log1" to DEBUG, I do get the DEBUG logs of Myclass in log1.log.

If you set the level of the Log1 appender to DEBUG, you say that you get 
the DEBUG logs of Myclass in log1.log. Isn't that what you want?

Re: class specific logging level

Posted by aggarwal <ak...@gmail.com>.
Hi,

I have tried it with the following configuration :


<appender name="Log1" class="org.apache.log4j.RollingFileAppender">
	
	
	
        
	
        <layout class="org.apache.log4j.PatternLayout">
	              
	</layout>
</appender>

<logger name="MyClass" additivity="true">
	<level value="DEBUG" />
</logger>

<root>
	<priority value="INFO" />
	<appender-ref ref="Log1" />
</root>


I want MyClass logs of DEBUG level and all other classes of ERROR in
"log1.log" file as mentioned in logger "Log1". But it isnt happening. Am not
getting any DEBUG logs in "log1.log" whereas if I set the level in appender
"Log1" to DEBUG, I do get the DEBUG logs of Myclass in log1.log. I am sorry
if am still making some mistake here. Please correct me where am I wrong.

Thanks for such quick replies.





Jacob Kjome wrote:
> 
> 
> What I've provided does exactly what you are asking for.  Setting your
> class 
> logging level to DEBUG overrides the inherited level from root for the 
> specified logger name.  Why don't you just try it and see what it does
> rather 
> than speculate on why you believe it wouldn't work?  You can also read try 
> reading the docs...
> 
> http://logging.apache.org/log4j/1.2/manual.html
> 
> Jake
> 
> On Thu, 7 Jun 2012 20:44:05 -0700 (PDT)
>  aggarwal <ak...@gmail.com> wrote:
>> 
>> So when root level is ERROR and i set Myclass level to DEBUG, how will
>> the
>> Myclass's DEBUG logs get logged since the root level is ERROR and it will
>> block the DEBUG logs ? What i know is that, if I set root level to DEBUG
>> and
>> some particular class (say Myclass) logger level to ERROR then, all
>> classes'
>> logs of DEBUG will get logged but not of Myclass as its restricted to
>> ERROR.
>> But what I want is the vice-versa. I want ERROR level of all classes and
>> DEBUG of only few important classes. I am new to log4j so maybe what i am
>> sayin is wrong.
>> 
>> 
>> 
>> Jacob Kjome wrote:
>>> 
>>> 
>>> If you name your loggers by class name, then sure.  This is standard
>>> logging 
>>> configuration, not some extra special workaround.
>>> 
>>> <logger name="com.mypackage.Myclass">
>>>     <level value="debug"/>
>>>     <!-- inherits A1 appender from root, applies only to
>>> com.mypackage.MyClass 
>>> -->
>>> </logger>
>>> <logger name="com.myotherpackage">
>>>     <level value="debug"/>
>>>     <!-- inherits A1 appender from root, applies to all classes in 
>>> "com.myotherpackage" -->
>>> </logger>
>>> <root>
>>>     <level value="error"/>
>>>     <appender-ref ref="A1"/>
>>> </root>
>>> 
>>> 
>>> Jake
>>> 
>>> On Thu, 7 Jun 2012 01:51:07 -0700 (PDT)
>>>  aggarwal <ak...@gmail.com> wrote:
>>>> 
>>>> Hi,
>>>> 
>>>> Is it possible to set logging level for few selected classes in
>>>> appender
>>>> to
>>>> DEBUG and rest all ERROR ? Is there any combination of filter that can
>>>> do
>>>> this ?
>>>> -- 
>>>> View this message in context: 
>>>>http://old.nabble.com/class-specific-logging-level-tp33974515p33974515.html
>>>> Sent from the Log4j - Users mailing list archive at Nabble.com.
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> 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
>>> 
>>> 
>>> 
>> 
>> -- 
>> View this message in context: 
>>http://old.nabble.com/class-specific-logging-level-tp33974515p33979415.html
>> Sent from the Log4j - Users mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> 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
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/class-specific-logging-level-tp33974515p33982398.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: class specific logging level

Posted by Jacob Kjome <ho...@visi.com>.
What I've provided does exactly what you are asking for.  Setting your class 
logging level to DEBUG overrides the inherited level from root for the 
specified logger name.  Why don't you just try it and see what it does rather 
than speculate on why you believe it wouldn't work?  You can also read try 
reading the docs...

http://logging.apache.org/log4j/1.2/manual.html

Jake

On Thu, 7 Jun 2012 20:44:05 -0700 (PDT)
 aggarwal <ak...@gmail.com> wrote:
> 
> So when root level is ERROR and i set Myclass level to DEBUG, how will the
> Myclass's DEBUG logs get logged since the root level is ERROR and it will
> block the DEBUG logs ? What i know is that, if I set root level to DEBUG and
> some particular class (say Myclass) logger level to ERROR then, all classes'
> logs of DEBUG will get logged but not of Myclass as its restricted to ERROR.
> But what I want is the vice-versa. I want ERROR level of all classes and
> DEBUG of only few important classes. I am new to log4j so maybe what i am
> sayin is wrong.
> 
> 
> 
> Jacob Kjome wrote:
>> 
>> 
>> If you name your loggers by class name, then sure.  This is standard
>> logging 
>> configuration, not some extra special workaround.
>> 
>> <logger name="com.mypackage.Myclass">
>>     <level value="debug"/>
>>     <!-- inherits A1 appender from root, applies only to
>> com.mypackage.MyClass 
>> -->
>> </logger>
>> <logger name="com.myotherpackage">
>>     <level value="debug"/>
>>     <!-- inherits A1 appender from root, applies to all classes in 
>> "com.myotherpackage" -->
>> </logger>
>> <root>
>>     <level value="error"/>
>>     <appender-ref ref="A1"/>
>> </root>
>> 
>> 
>> Jake
>> 
>> On Thu, 7 Jun 2012 01:51:07 -0700 (PDT)
>>  aggarwal <ak...@gmail.com> wrote:
>>> 
>>> Hi,
>>> 
>>> Is it possible to set logging level for few selected classes in appender
>>> to
>>> DEBUG and rest all ERROR ? Is there any combination of filter that can do
>>> this ?
>>> -- 
>>> View this message in context: 
>>>http://old.nabble.com/class-specific-logging-level-tp33974515p33974515.html
>>> Sent from the Log4j - Users mailing list archive at Nabble.com.
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> 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
>> 
>> 
>> 
> 
> -- 
> View this message in context: 
>http://old.nabble.com/class-specific-logging-level-tp33974515p33979415.html
> Sent from the Log4j - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> 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: class specific logging level

Posted by aggarwal <ak...@gmail.com>.
Due to some reason, the following text isn't visible in the message but is
when m replying back to this message.

<appender name="Log2" class="org.apache.log4j.RollingFileAppender">
				
		
		
		
		
		<layout class="org.apache.log4j.PatternLayout"/>
</appender>

I have to work on RollingFileAppender only. 


aggarwal wrote:
> 
> I tried with both ConsoleAppender and RollingFileAppender and found out
> that the behavior shown in ConsoleAppender isn't shown in
> RollingFileAppender.
> 
> Console :
> --------
> MyClass error
> MyClass info
> MyClass debug
> OtherClass error
> ***************************
> Log File:
> --------
> MyClass error
> OtherClass error
> **************************
> 
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
>  debug="true">
>  <appender name="Log1" class="org.apache.log4j.ConsoleAppender">
>   <layout class="org.apache.log4j.PatternLayout"/>
>  </appender>
>  
>  <appender name="Log2" class="org.apache.log4j.RollingFileAppender">
> 				
> 		
> 		
> 		
> 		
> 		<layout class="org.apache.log4j.PatternLayout"/>
> 	</appender>
> 
>  <logger name="com.pkg.MyClass" additivity="true">
>   <level value="DEBUG" />
>  </logger>
> 
>  <root>
>   <level value="ERROR" />
>   <appender-ref ref="Log1" />
>   <appender-ref ref="Log2" />
>  </root>
> </log4j:configuration>
> ***************************
> MyClass.java
> -------------
> 
> package com.pkg;
> 
> import org.apache.log4j.Logger;
> 
> public class MyClass {
> 	static Logger logger = Logger.getLogger(MyClass.class);
> 	public static void main (String[] args) {
> 		logger.error ("MyClass error");
> 		logger.info ("MyClass info");
> 		logger.debug ("MyClass debug");
> 		OtherClass.doThings();
> 	}
> }
> ***********************
> OtherClass .java
> ----------------
> package com.pkg;
> 
> import org.apache.log4j.Logger;
> 
> public class OtherClass {
> 	static Logger logger = Logger.getLogger(OtherClass.class);
> 	public static void doThings () {
> 		logger.error ("OtherClass error");
> 		logger.info ("OtherClass info");
> 		logger.debug ("OtherClass debug");
> 	} 
> }
> 
> 
> 
> Douglas E Wegscheid wrote:
>> 
>> root being set to ERROR will not block the Myclass DEBUG; the 
>> more-specific Myclass logger setting overrides the root setting.
>> 
>> Have you actually tried this?
>> 
>> package com.pkg;
>> 
>> import org.apache.log4j.Logger;
>> import com.other.OtherClass;
>> 
>> public class MyClass {
>>   static Logger logger = Logger.getLogger(MyClass.class);
>>   public static void main (String[] args) {
>>     logger.error ("MyClass error");
>>     logger.info ("MyClass info");
>>     logger.debug ("MyClass debug");
>>     OtherClass.doThings();
>>   }
>> }
>> 
>> --
>> 
>> package com.other;
>> import org.apache.log4j.Logger;
>> 
>> public class OtherClass {
>>   static Logger logger = Logger.getLogger(OtherClass.class);
>>   public static void doThings () {
>>     logger.error ("OtherClass error");
>>     logger.info ("OtherClass info");
>>     logger.debug ("OtherClass debug");
>>   }
>> }
>> 
>> --
>> 
>> <?xml version="1.0" encoding="UTF-8" ?>
>> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
>> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
>>  debug="true">
>>  <appender name="Log1" class="org.apache.log4j.ConsoleAppender">
>>   <layout class="org.apache.log4j.PatternLayout"/>
>>  </appender>
>> 
>>  <logger name="com.pkg.MyClass" additivity="true">
>>   <level value="DEBUG" />
>>  </logger>
>> 
>>  <root>
>>   <level value="INFO" />
>>   <appender-ref ref="Log1" />
>>  </root>
>> </log4j:configuration>
>> 
>> -- results in --
>> 
>> MyClass error
>> MyClass info
>> MyClass debug
>> OtherClass error
>> OtherClass info
>> 
>> 
>> 
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/class-specific-logging-level-tp33974515p33991122.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: class specific logging level

Posted by aggarwal <ak...@gmail.com>.
I tried with both ConsoleAppender and RollingFileAppender and found out that
the behavior shown in ConsoleAppender isn't shown in RollingFileAppender.

Console :
--------
MyClass error
MyClass info
MyClass debug
OtherClass error
***************************
Log File:
--------
MyClass error
OtherClass error
**************************

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
 debug="true">
 <appender name="Log1" class="org.apache.log4j.ConsoleAppender">
  <layout class="org.apache.log4j.PatternLayout"/>
 </appender>
 
 <appender name="Log2" class="org.apache.log4j.RollingFileAppender">
				
		
		
		
		
		<layout class="org.apache.log4j.PatternLayout"/>
	</appender>

 <logger name="com.pkg.MyClass" additivity="true">
  <level value="DEBUG" />
 </logger>

 <root>
  <level value="ERROR" />
  <appender-ref ref="Log1" />
  <appender-ref ref="Log2" />
 </root>
</log4j:configuration>
***************************
MyClass.java
-------------

package com.pkg;

import org.apache.log4j.Logger;

public class MyClass {
	static Logger logger = Logger.getLogger(MyClass.class);
	public static void main (String[] args) {
		logger.error ("MyClass error");
		logger.info ("MyClass info");
		logger.debug ("MyClass debug");
		OtherClass.doThings();
	}
}
***********************
OtherClass .java
----------------
package com.pkg;

import org.apache.log4j.Logger;

public class OtherClass {
	static Logger logger = Logger.getLogger(OtherClass.class);
	public static void doThings () {
		logger.error ("OtherClass error");
		logger.info ("OtherClass info");
		logger.debug ("OtherClass debug");
	} 
}



Douglas E Wegscheid wrote:
> 
> root being set to ERROR will not block the Myclass DEBUG; the 
> more-specific Myclass logger setting overrides the root setting.
> 
> Have you actually tried this?
> 
> package com.pkg;
> 
> import org.apache.log4j.Logger;
> import com.other.OtherClass;
> 
> public class MyClass {
>   static Logger logger = Logger.getLogger(MyClass.class);
>   public static void main (String[] args) {
>     logger.error ("MyClass error");
>     logger.info ("MyClass info");
>     logger.debug ("MyClass debug");
>     OtherClass.doThings();
>   }
> }
> 
> --
> 
> package com.other;
> import org.apache.log4j.Logger;
> 
> public class OtherClass {
>   static Logger logger = Logger.getLogger(OtherClass.class);
>   public static void doThings () {
>     logger.error ("OtherClass error");
>     logger.info ("OtherClass info");
>     logger.debug ("OtherClass debug");
>   }
> }
> 
> --
> 
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
>  debug="true">
>  <appender name="Log1" class="org.apache.log4j.ConsoleAppender">
>   <layout class="org.apache.log4j.PatternLayout"/>
>  </appender>
> 
>  <logger name="com.pkg.MyClass" additivity="true">
>   <level value="DEBUG" />
>  </logger>
> 
>  <root>
>   <level value="INFO" />
>   <appender-ref ref="Log1" />
>  </root>
> </log4j:configuration>
> 
> -- results in --
> 
> MyClass error
> MyClass info
> MyClass debug
> OtherClass error
> OtherClass info
> 
> 
> 
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/class-specific-logging-level-tp33974515p33991121.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: class specific logging level

Posted by aggarwal <ak...@gmail.com>.
So, I found out the why RollingFileAppender wasn't behaving like
ConsoleAppender. Because I had mentioned a threshold level in
RollingFileAppender but not in ConsoleAppender. Removing threshold tag from
RollingFileAppender worked.


aggarwal wrote:
> 
> I think I have found the solution to my problem.
> 
> This thing is working with "org.apache.log4j.rolling.RollingFileAppender"
> but not with "org.apache.log4j.RollingFileAppender"
> 
> Thanks for helping me out. :)
> 
> 
> 
> Douglas E Wegscheid wrote:
>> 
>> root being set to ERROR will not block the Myclass DEBUG; the 
>> more-specific Myclass logger setting overrides the root setting.
>> 
>> Have you actually tried this?
>> 
>> package com.pkg;
>> 
>> import org.apache.log4j.Logger;
>> import com.other.OtherClass;
>> 
>> public class MyClass {
>>   static Logger logger = Logger.getLogger(MyClass.class);
>>   public static void main (String[] args) {
>>     logger.error ("MyClass error");
>>     logger.info ("MyClass info");
>>     logger.debug ("MyClass debug");
>>     OtherClass.doThings();
>>   }
>> }
>> 
>> --
>> 
>> package com.other;
>> import org.apache.log4j.Logger;
>> 
>> public class OtherClass {
>>   static Logger logger = Logger.getLogger(OtherClass.class);
>>   public static void doThings () {
>>     logger.error ("OtherClass error");
>>     logger.info ("OtherClass info");
>>     logger.debug ("OtherClass debug");
>>   }
>> }
>> 
>> --
>> 
>> <?xml version="1.0" encoding="UTF-8" ?>
>> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
>> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
>>  debug="true">
>>  <appender name="Log1" class="org.apache.log4j.ConsoleAppender">
>>   <layout class="org.apache.log4j.PatternLayout"/>
>>  </appender>
>> 
>>  <logger name="com.pkg.MyClass" additivity="true">
>>   <level value="DEBUG" />
>>  </logger>
>> 
>>  <root>
>>   <level value="INFO" />
>>   <appender-ref ref="Log1" />
>>  </root>
>> </log4j:configuration>
>> 
>> -- results in --
>> 
>> MyClass error
>> MyClass info
>> MyClass debug
>> OtherClass error
>> OtherClass info
>> 
>> 
>> 
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/class-specific-logging-level-tp33974515p33992013.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: class specific logging level

Posted by aggarwal <ak...@gmail.com>.
I think I have found the solution to my problem.

This thing is working with "org.apache.log4j.rolling.RollingFileAppender"
but not with "org.apache.log4j.RollingFileAppender"

Thanks for helping me out. :)



Douglas E Wegscheid wrote:
> 
> root being set to ERROR will not block the Myclass DEBUG; the 
> more-specific Myclass logger setting overrides the root setting.
> 
> Have you actually tried this?
> 
> package com.pkg;
> 
> import org.apache.log4j.Logger;
> import com.other.OtherClass;
> 
> public class MyClass {
>   static Logger logger = Logger.getLogger(MyClass.class);
>   public static void main (String[] args) {
>     logger.error ("MyClass error");
>     logger.info ("MyClass info");
>     logger.debug ("MyClass debug");
>     OtherClass.doThings();
>   }
> }
> 
> --
> 
> package com.other;
> import org.apache.log4j.Logger;
> 
> public class OtherClass {
>   static Logger logger = Logger.getLogger(OtherClass.class);
>   public static void doThings () {
>     logger.error ("OtherClass error");
>     logger.info ("OtherClass info");
>     logger.debug ("OtherClass debug");
>   }
> }
> 
> --
> 
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
>  debug="true">
>  <appender name="Log1" class="org.apache.log4j.ConsoleAppender">
>   <layout class="org.apache.log4j.PatternLayout"/>
>  </appender>
> 
>  <logger name="com.pkg.MyClass" additivity="true">
>   <level value="DEBUG" />
>  </logger>
> 
>  <root>
>   <level value="INFO" />
>   <appender-ref ref="Log1" />
>  </root>
> </log4j:configuration>
> 
> -- results in --
> 
> MyClass error
> MyClass info
> MyClass debug
> OtherClass error
> OtherClass info
> 
> 
> 
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/class-specific-logging-level-tp33974515p33991200.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: class specific logging level

Posted by Douglas E Wegscheid <Do...@whirlpool.com>.
root being set to ERROR will not block the Myclass DEBUG; the 
more-specific Myclass logger setting overrides the root setting.

Have you actually tried this?

package com.pkg;

import org.apache.log4j.Logger;
import com.other.OtherClass;

public class MyClass {
  static Logger logger = Logger.getLogger(MyClass.class);
  public static void main (String[] args) {
    logger.error ("MyClass error");
    logger.info ("MyClass info");
    logger.debug ("MyClass debug");
    OtherClass.doThings();
  }
}

--

package com.other;
import org.apache.log4j.Logger;

public class OtherClass {
  static Logger logger = Logger.getLogger(OtherClass.class);
  public static void doThings () {
    logger.error ("OtherClass error");
    logger.info ("OtherClass info");
    logger.debug ("OtherClass debug");
  }
}

--

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
 debug="true">
 <appender name="Log1" class="org.apache.log4j.ConsoleAppender">
  <layout class="org.apache.log4j.PatternLayout"/>
 </appender>

 <logger name="com.pkg.MyClass" additivity="true">
  <level value="DEBUG" />
 </logger>

 <root>
  <level value="INFO" />
  <appender-ref ref="Log1" />
 </root>
</log4j:configuration>

-- results in --

MyClass error
MyClass info
MyClass debug
OtherClass error
OtherClass info





Re: class specific logging level

Posted by aggarwal <ak...@gmail.com>.
So when root level is ERROR and i set Myclass level to DEBUG, how will the
Myclass's DEBUG logs get logged since the root level is ERROR and it will
block the DEBUG logs ? What i know is that, if I set root level to DEBUG and
some particular class (say Myclass) logger level to ERROR then, all classes'
logs of DEBUG will get logged but not of Myclass as its restricted to ERROR.
But what I want is the vice-versa. I want ERROR level of all classes and
DEBUG of only few important classes. I am new to log4j so maybe what i am
sayin is wrong.



Jacob Kjome wrote:
> 
> 
> If you name your loggers by class name, then sure.  This is standard
> logging 
> configuration, not some extra special workaround.
> 
> <logger name="com.mypackage.Myclass">
>     <level value="debug"/>
>     <!-- inherits A1 appender from root, applies only to
> com.mypackage.MyClass 
> -->
> </logger>
> <logger name="com.myotherpackage">
>     <level value="debug"/>
>     <!-- inherits A1 appender from root, applies to all classes in 
> "com.myotherpackage" -->
> </logger>
> <root>
>     <level value="error"/>
>     <appender-ref ref="A1"/>
> </root>
> 
> 
> Jake
> 
> On Thu, 7 Jun 2012 01:51:07 -0700 (PDT)
>  aggarwal <ak...@gmail.com> wrote:
>> 
>> Hi,
>> 
>> Is it possible to set logging level for few selected classes in appender
>> to
>> DEBUG and rest all ERROR ? Is there any combination of filter that can do
>> this ?
>> -- 
>> View this message in context: 
>>http://old.nabble.com/class-specific-logging-level-tp33974515p33974515.html
>> Sent from the Log4j - Users mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> 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
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/class-specific-logging-level-tp33974515p33979415.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: class specific logging level

Posted by Jacob Kjome <ho...@visi.com>.
If you name your loggers by class name, then sure.  This is standard logging 
configuration, not some extra special workaround.

<logger name="com.mypackage.Myclass">
    <level value="debug"/>
    <!-- inherits A1 appender from root, applies only to com.mypackage.MyClass 
-->
</logger>
<logger name="com.myotherpackage">
    <level value="debug"/>
    <!-- inherits A1 appender from root, applies to all classes in 
"com.myotherpackage" -->
</logger>
<root>
    <level value="error"/>
    <appender-ref ref="A1"/>
</root>


Jake

On Thu, 7 Jun 2012 01:51:07 -0700 (PDT)
 aggarwal <ak...@gmail.com> wrote:
> 
> Hi,
> 
> Is it possible to set logging level for few selected classes in appender to
> DEBUG and rest all ERROR ? Is there any combination of filter that can do
> this ?
> -- 
> View this message in context: 
>http://old.nabble.com/class-specific-logging-level-tp33974515p33974515.html
> Sent from the Log4j - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> 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