karaf-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikevan <mvangeert...@comcast.net>
Subject Re: Using custom log4j appenders under Karaf 2.1.4
Date Mon, 18 Jul 2011 23:19:05 GMT
Oops!  Looks like there was a typo. Try this instead:
# mypackage.subpackage appender
log4j.logger.mypackage.subpackage=<level>, subpackage 
log4j.appender.subpackage=org.apache.log4j.RollingFileAppender 
log4j.appender.subpackage.layout=org.apache.log4j.PatternLayout 
log4j.appender.subpackage.layout.ConversionPattern=<pattern>
log4j.appender.subpackage.file=${karaf.data}/log/subpackage.log 
log4j.appender.subpackage.append=true 
log4j.appender.subpackage.maxFileSize=10MB 
log4j.appender.subpackage.maxBackupIndex=10 




mikevan wrote:
> 
> Echo,
> 
> Yes, but instead of making you google it, I'll just tell you how its done.
> :-)
> 
> First, its good to remember that in log4j, logging can be set on a package
> level.  This can be done in Karaf using the following console command
> 
> karaf@root> log:set <level> mypackage.subpackage
> 
> This will set the logging for that specific package to <level>.
> 
> In Karaf 3.x, you can also filter for a specific package using the
> following command:
> 
> karaf@root> log:get mypackage.subpackage
> 
> Some caveats with the log console commands.  With the exception of
> log:set, your commands won't affect the logs placed on the file system.
> For example, if you type log:clear, you won't have access to any log
> messages written out prior to executing the log:clear command.  However,
> log:clear won't remove those older log messages from the log directory.
> This is because all of the logging commands don't actually work against
> your log files.  Instead, the logging commands look for PaxLoggingEvents
> inside of Karaf.  So, if you accidentally run log:clear, dont' worry, you
> won't lose all of your log messages.  However, if you accidentally set
> your logging level to DEBUG or TRACE, this change will result in all of
> your logging messages being set to the new level and your logs filling up
> very quickly.
> 
> So, the log messages are great but they wont' get you what you want, which
> is a file containing only the messages from a given package.  To do that,
> you simply create a logger for your package, and then create a
> RollingFileAppender for that logger.  Here's an example of what to place
> in your org.ops4j.pax.logging.cfg file.
> 
> # mypackage.subpackage appenderlog4j.logger.mypackage.subpackage= <level>,
> subpackage
> log4j.appender.subpackage=org.apache.log4j.RollingFileAppender
> log4j.appender.subpackage.layout=org.apache.log4j.PatternLayout
> log4j.appender.subpackage.layout.ConversionPattern=<pattern>
> log4j.appender.subpackage.file=${karaf.data}/log/subpackage.log
> log4j.appender.subpackage.append=true
> log4j.appender.subpackage.maxFileSize=10MB
> log4j.appender.subpackage.maxBackupIndex=10
> 
> Now, some caveats.  If your "subpackage" has camel routes that you'd like
> logged into your subpackage log file, they won't appear. This is because
> the messages from your camel routes are generated from org.apache.camel,
> and not by your subpackage.  I dont' really know a way to get those camel
> message froms subpackage to appear in your subpackage log file.  Also, all
> messages are still going to be written into your karaf.log file. So, if
> you are seeing some strangeness and can't diagnose it in your
> subpackage.log file, check out your karaf.log.
> 
> Please let me know if this answers your question.
> 
> 
> Echo wrote:
>> 
>> @ mikevan: 
>> regarding ur 2nd question :
>>  2) is there an example of  how to get log messages written into
>> different log files? 
>> 
>> Did u manage it as um now messing around the file but I couldn't find out
>> a solution yet
>> 
> 


-----
Mike Van
--
View this message in context: http://karaf.922171.n3.nabble.com/Using-custom-log4j-appenders-under-Karaf-2-1-4-tp2781811p3180945.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Mime
View raw message