logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aggarwal <akansha.ag...@gmail.com>
Subject Re: class specific logging level
Date Mon, 11 Jun 2012 05:07:52 GMT

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


Mime
View raw message