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 Scott Smith <SS...@MainstreamData.com> on 2003/11/12 01:13:45 UTC

Newbie question on setting different levels

I've been reading through documentation on log4j and thought I understood
how everything works.  But there is something I'm missing.  

Since several of the Jakarta libraries seem to log to the root logger, I
wanted to set up the root logger with the appenders.  Then I would set the
root logger to pass ERROR or above and my own logger to pass DEBUG or above
(so I'd see everything from my app, but only errors from the libraries).
Based on that, I generated the following configuration file.

----------------------------------------------------------------------------
--
<?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="CONSOLE" class = "org.apache.log4j.ConsoleAppender">
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="%d [%t] %-5p
%c %m%n"/>
		</layout>
	</appender>
	
	<appender name="FILE" class =
"org.apache.log4j.DailyRollingFileAppender">
		<param name="file" value="./Logs/log"/>
		<param name="ImmediateFlush" value="true"/>
		<param name="Append" value="true"/>
		<param name="DatePattern" value="'.' yyyy-MM-dd"/>
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="%d %-5p
%m%n"/>
		</layout>
	</appender>
	
	<logger name="com.mainstreamdata.messager">
		<level value="debug"/>
	</logger>
	
	<root>
		<priority value="error" />
		<appender-ref ref="CONSOLE"/>
		<appender-ref ref="FILE"/>
	</root>
</log4j:configuration>
----------------------------------------------------------------------------
-------------

When I execute:
	DOMConfigurator.configure("log4j.xml");
Everything seems to be fine and I see the following from log4j:

----------------------------------------------------------------------------
log4j: Threshold ="null".
log4j: Retreiving an instance of org.apache.log4j.Logger.
log4j: Setting [com.mainstreamdata.messager] additivity to [true].
log4j: Level value for com.mainstreamdata.messager is  [debug].
log4j: com.mainstreamdata.messager level set to DEBUG
log4j: Level value for root is  [error].
log4j: root level set to ERROR
log4j: Class name: [org.apache.log4j.ConsoleAppender]
log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
log4j: Setting property [conversionPattern] to [%d [%t] %-5p %c %m%n].
log4j: Adding appender named [CONSOLE] to category [root].
log4j: Class name: [org.apache.log4j.DailyRollingFileAppender]
log4j: Setting property [file] to [./Logs/log].
log4j: Setting property [immediateFlush] to [true].
log4j: Setting property [append] to [true].
log4j: Setting property [datePattern] to ['.' yyyy-MM-dd].
log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
log4j: Setting property [conversionPattern] to [%d %-5p %m%n].
log4j: setFile called: ./Logs/log, true
log4j: setFile ended
log4j: Appender [FILE] to be rolled at midnight.
log4j: Adding appender named [FILE] to category [root].
-------------------------------------------------------------------

All of which looks OK to me.  Here's the problem.  I don't see any of my
DEBUG logs go to either appender.  In fact, if I execute the following line
of code:

	System.out.println("Effective Level for " + lggr.getName() + " is "
+ lggr.getEffectiveLevel());

It says:

	Effective Level for com.mainstreamdata.messager is INFO

I don't want INFO; I want DEBUG.  If I hadn't set my logger in the config
file to DEBUG, I would have expected it to default to ERROR (the root logger
level).  I also tried enumerating through the logger repository (off of the
root logger) to see if I had something misspelled and I really had two
loggers enabled, but it only shows the one (non-root) logger.  Oh, and if I
set the level programmatically to DEBUG, it works as I expect.  Also, I
printed the effective level of the root logger and it showed up as ERROR
(which is what I said in the configuration file and so was also expected).
What am I missing????
		
Thanks for any help.

Scott Smith

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


Re: Newbie question on setting different levels

Posted by Paul Smith <pa...@lawlex.com.au>.
I have to admit that everything you have indicated here looks fine.  At
what point does the DOMConfigurator.configure("log4j.xml") call get
made? I am assuming here that it is called _before_ the call to
getEffectiveLevel(). By default all Loggers will be INFO until a
configuration sets to otherwise.

cheers,

Paul Smith


On Wed, 2003-11-12 at 11:13, Scott Smith wrote:
> I've been reading through documentation on log4j and thought I understood
> how everything works.  But there is something I'm missing.  
> 
> Since several of the Jakarta libraries seem to log to the root logger, I
> wanted to set up the root logger with the appenders.  Then I would set the
> root logger to pass ERROR or above and my own logger to pass DEBUG or above
> (so I'd see everything from my app, but only errors from the libraries).
> Based on that, I generated the following configuration file.
> 
> ----------------------------------------------------------------------------
> --
> <?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="CONSOLE" class = "org.apache.log4j.ConsoleAppender">
> 		<layout class="org.apache.log4j.PatternLayout">
> 			<param name="ConversionPattern" value="%d [%t] %-5p
> %c %m%n"/>
> 		</layout>
> 	</appender>
> 	
> 	<appender name="FILE" class =
> "org.apache.log4j.DailyRollingFileAppender">
> 		<param name="file" value="./Logs/log"/>
> 		<param name="ImmediateFlush" value="true"/>
> 		<param name="Append" value="true"/>
> 		<param name="DatePattern" value="'.' yyyy-MM-dd"/>
> 		<layout class="org.apache.log4j.PatternLayout">
> 			<param name="ConversionPattern" value="%d %-5p
> %m%n"/>
> 		</layout>
> 	</appender>
> 	
> 	<logger name="com.mainstreamdata.messager">
> 		<level value="debug"/>
> 	</logger>
> 	
> 	<root>
> 		<priority value="error" />
> 		<appender-ref ref="CONSOLE"/>
> 		<appender-ref ref="FILE"/>
> 	</root>
> </log4j:configuration>
> ----------------------------------------------------------------------------
> -------------
> 
> When I execute:
> 	DOMConfigurator.configure("log4j.xml");
> Everything seems to be fine and I see the following from log4j:
> 
> ----------------------------------------------------------------------------
> log4j: Threshold ="null".
> log4j: Retreiving an instance of org.apache.log4j.Logger.
> log4j: Setting [com.mainstreamdata.messager] additivity to [true].
> log4j: Level value for com.mainstreamdata.messager is  [debug].
> log4j: com.mainstreamdata.messager level set to DEBUG
> log4j: Level value for root is  [error].
> log4j: root level set to ERROR
> log4j: Class name: [org.apache.log4j.ConsoleAppender]
> log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
> log4j: Setting property [conversionPattern] to [%d [%t] %-5p %c %m%n].
> log4j: Adding appender named [CONSOLE] to category [root].
> log4j: Class name: [org.apache.log4j.DailyRollingFileAppender]
> log4j: Setting property [file] to [./Logs/log].
> log4j: Setting property [immediateFlush] to [true].
> log4j: Setting property [append] to [true].
> log4j: Setting property [datePattern] to ['.' yyyy-MM-dd].
> log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
> log4j: Setting property [conversionPattern] to [%d %-5p %m%n].
> log4j: setFile called: ./Logs/log, true
> log4j: setFile ended
> log4j: Appender [FILE] to be rolled at midnight.
> log4j: Adding appender named [FILE] to category [root].
> -------------------------------------------------------------------
> 
> All of which looks OK to me.  Here's the problem.  I don't see any of my
> DEBUG logs go to either appender.  In fact, if I execute the following line
> of code:
> 
> 	System.out.println("Effective Level for " + lggr.getName() + " is "
> + lggr.getEffectiveLevel());
> 
> It says:
> 
> 	Effective Level for com.mainstreamdata.messager is INFO
> 
> I don't want INFO; I want DEBUG.  If I hadn't set my logger in the config
> file to DEBUG, I would have expected it to default to ERROR (the root logger
> level).  I also tried enumerating through the logger repository (off of the
> root logger) to see if I had something misspelled and I really had two
> loggers enabled, but it only shows the one (non-root) logger.  Oh, and if I
> set the level programmatically to DEBUG, it works as I expect.  Also, I
> printed the effective level of the root logger and it showed up as ERROR
> (which is what I said in the configuration file and so was also expected).
> What am I missing????
> 		
> Thanks for any help.
> 
> Scott Smith
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org


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