logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adrian Janssen" <a.jans...@videonetworks.com>
Subject RE: log4j.properties - How to parse outpu to multiple files
Date Thu, 09 Oct 2003 08:46:47 GMT
actually there is some filtering ability available in the normal properties
file, probably enough for you needs:

log4j.appender.MyAppender.Threshold=INFO

Cheers
Adrian

-----Original Message-----
From: Kevin Dougan [mailto:kdougan@rim.net]
Sent: 09 October 2003 05:16
To: Log4J Users List
Subject: RE: log4j.properties - How to parse outpu to multiple files


Eureka! I have a solution! I now have my logging messages split out into the
4 types that I support: DEBUG, INFO, WARN & ERROR. My app-debug.log file
contains everything, down to my app-error.log file which only contains
errors!

Why is it that these moments tend to occur after midnight...   :-)

Note: I switched from log4j.properties to log4j.xml in order to take
advantage of filters, which aren't supported in the properties file.

Here's my log4j.xml file, enjoy:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>

	<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
		<layout class="org.apache.log4j.PatternLayout">
  		     <param name="ConversionPattern" value="%c %d{ISO8601}
-- %p -- %m%n"/>
		</layout>
	</appender>

	<appender name="DEBUG" class="org.apache.log4j.RollingFileAppender">
      <param name="File" value="C:\\logs\\app-debug.log"/>
      <param name="Append" value="true"/>
      <param name="MaxFileSize" value="500KB"/>
      <param name="MaxBackupIndex" value="2"/>
		<layout class="org.apache.log4j.PatternLayout">
  		     <param name="ConversionPattern" value="%c %d{ISO8601}
-- %p -- %m%n"/>
		</layout>
	</appender>

	<appender name="INFO" class="org.apache.log4j.RollingFileAppender">
      <param name="File" value="C:\\logs\\app-info.log"/>
      <param name="Append" value="true"/>
      <param name="MaxFileSize" value="500KB"/>
      <param name="MaxBackupIndex" value="2"/>
		<layout class="org.apache.log4j.PatternLayout">
  		     <param name="ConversionPattern" value="%c %d{ISO8601}
-- %p -- %m%n"/>
		</layout>
		<filter class="org.apache.log4j.varia.LevelRangeFilter">
			<param name="LevelMin" value="INFO" />
		</filter>
   </appender>

	<appender name="WARN" class="org.apache.log4j.RollingFileAppender">
      <param name="File" value="C:\\logs\\app-warn.log"/>
      <param name="Append" value="true"/>
      <param name="MaxFileSize" value="500KB"/>
      <param name="MaxBackupIndex" value="2"/>
		<layout class="org.apache.log4j.PatternLayout">
  		     <param name="ConversionPattern" value="%c %d{ISO8601}
-- %p -- %m%n"/>
		</layout>
		<filter class="org.apache.log4j.varia.LevelRangeFilter">
			<param name="LevelMin" value="WARN" />
		</filter>
   </appender>

	<appender name="ERROR" class="org.apache.log4j.RollingFileAppender">
      <param name="File" value="C:\\logs\\app-error.log"/>
      <param name="Append" value="true"/>
      <param name="MaxFileSize" value="500KB"/>
      <param name="MaxBackupIndex" value="2"/>
		<layout class="org.apache.log4j.PatternLayout">
  		     <param name="ConversionPattern" value="%c %d{ISO8601}
-- %p -- %m%n"/>
		</layout>
		<filter class="org.apache.log4j.varia.LevelRangeFilter">
			<param name="LevelMin" value="ERROR" />
		</filter>
   </appender>

	<root>
		<priority value="debug"/>
   	<appender-ref ref="STDOUT"/>
     	<appender-ref ref="DEBUG"/>
   	<appender-ref ref="INFO"/>
   	<appender-ref ref="WARN"/>
   	<appender-ref ref="ERROR"/>
	</root>

</log4j:configuration>

-----Original Message-----
From: Kevin Dougan 
Sent: October 8, 2003 3:09 PM
To: log4j-user@jakarta.apache.org
Subject: log4j.properties - How to parse outpu to multiple files


Greetings log4j list!

I'd like my logging output to be sent to multiple files at once. However, I
only want ERRORs in the app-error.log file, DEBUG in the app-debug.log file,
etc. As a potential compromise, I would be OK if I was able to at least
reduce the types of log messages as the severity increased.

Can anyone assist with my log4.properties file? I've included a copy below,
but note that this config sends all the logging output to all files.

In addition, is there a way to avoid all the duplication in this config
file, so I just have to change the name of the output file in each case, and
inherit all the RollingFileAppender settings as I define each file?

Thanks!

log4j.threshold=ALL
log4j.rootLogger=ALL, stdout, DebugAppender, InfoAppender, WarnAppender,
ErrorAppender

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%c %d{ISO8601} -- %p -- %m%n

log4j.logger.DebugAppender.access=DEBUG
log4j.appender.DebugAppender=org.apache.log4j.RollingFileAppender
log4j.appender.DebugAppender.File=C:\\logs\\app-debug.log
log4j.appender.DebugAppender.MaxFileSize=500KB
log4j.appender.DebugAppender.MaxBackupIndex=10
log4j.appender.DebugAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.DebugAppender.layout.ConversionPattern=%c %d{ISO8601} -- %p
-- %m%n

log4j.logger.InfoAppender.access=INFO
log4j.appender.InfoAppender=org.apache.log4j.RollingFileAppender
log4j.appender.InfoAppender.File=C:\\logs\\app-info.log
log4j.appender.InfoAppender.MaxFileSize=500KB
log4j.appender.InfoAppender.MaxBackupIndex=10
log4j.appender.InfoAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.InfoAppender.layout.ConversionPattern=%c %d{ISO8601} -- %p --
%m%n

log4j.logger.WarnAppender.access=WARN
log4j.appender.WarnAppender=org.apache.log4j.RollingFileAppender
log4j.appender.WarnAppender.File=C:\\logs\\app-warn.log
log4j.appender.WarnAppender.MaxFileSize=500KB
log4j.appender.WarnAppender.MaxBackupIndex=10
log4j.appender.WarnAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.WarnAppender.layout.ConversionPattern=%c %d{ISO8601} -- %p --
%m%n

log4j.logger.ErrorAppender.access=ERROR
log4j.appender.ErrorAppender=org.apache.log4j.RollingFileAppender
log4j.appender.ErrorAppender.File=C:\\logs\\app-error.log
log4j.appender.ErrorAppender.MaxFileSize=500KB
log4j.appender.ErrorAppender.MaxBackupIndex=10
log4j.appender.ErrorAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.ErrorAppender.layout.ConversionPattern=%c %d{ISO8601} -- %p
-- %m%n

Kevin Dougan - kdougan@rim.net
Systems Architect
IT - Business Systems
Research In Motion - www.rim.com
BlackBerry Cell: 519-572-9417
Desk Phone: 519-888-7465  ext. 2451

This transmission may contain confidential or privileged material. Any use
of this information by anyone other than the intended recipient is
prohibited. If you have received this transmission in error, please
immediately reply to the sender and delete this information from your
system. Use, dissemination, distribution, or reproduction of this
transmission by unintended recipients is not authorized and may be unlawful.



---------------------------------------------------------------------
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


Mime
View raw message