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 St...@trw.com on 2003/02/22 00:40:20 UTC

Properties file advise needed

Does anyone know how I can specify the specific subclass for a Logger class for a named logger in a log4j property file (vice xml-based file)?  I extended Logger and am now receiving the dreaded ClassCastException when I explicitly set the level of a named logger.  I know why I am getting the exception and have also heard the arguments for wrapping instead of extending, but am stuck for reasons beyond the scope of this message.  I have seen examples of how to specify the logger class in an xml-based log4j config file, but need advise for property files.  We have quite a few of them. :)
 
In general, we have property files that look like:
 
 
log4j.rootCategory=DEBUG, console, file
 
log4j.logger.SomeNamedCategoryThatIsSortOfChattyAtDebug=INFO
 
# console appender settings
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.Threshold=INFO
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d|%p|%c|%m%n
 
# file appender settings
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.Threshold=DEBUG
log4j.appender.file.File=filename.log
log4j.appender.file.Append=true
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d|%p|%c|%m%n
log4j.appender.file.DatePattern='.'yyyy-MM-dd
 
 
In the example above, the Logger named "SomeNamedCategoryThatIsSortOfChattyAtDebug" is not of type Logger, but is of a subtype of Logger.  I need to let log4j know the subtype before it instantiates one first as type Logger to avoid the ClassCastException when I try to cast it to my custom Logger type later on.
 
Thanks in advance for any advice that you may be able to offer.
 
cheers,
Steve