karaf-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jean-Baptiste Onofré ...@nanthrax.net>
Subject Re: Karaf 4.2.4 - log to separate file
Date Wed, 17 Apr 2019 11:30:24 GMT
Hi,

I already answer to similar question last week and I also updated the
provided org.ops4j.pax.logging.cfg file.

You are not so far but you have a mistake in your config.

Can you try the following:

log4j2.logger.myClass.name = com.myproject.mypackage
log4j2.logger.myClass.level = INFO
log4j2.logger.myClass.additivity = false
log4j2.logger.myClass.appenderRef.MyClassAppender.ref = MyClassAppender

log4j2.appender.MyClassAppender.type = RollingRandomAccessFile
log4j2.appender.MyClassAppender.name = MyClassAppender
log4j2.appender.MyClassAppender.fileName = ${karaf.log}/myclass.log
log4j2.appender.MyClassAppender.filePattern = ${karaf.log}/myclass-%i.log
log4j2.appender.MyClassAppender.append = true
log4j2.appender.MyClassAppender.layout.type = PatternLayout
log4j2.appender.MyClassAppender.layout.pattern = ${log4j2.pattern}
log4j2.appender.MyClassAppender.policies.type = Policies
log4j2.appender.MyClassAppender.policies.size.type =
SizeBasedTriggeringPolicy
log4j2.appender.MyClassAppender.policies.size.size = 8MB

Regards
JB

On 17/04/2019 13:08, abdelb wrote:
> I want logs that come from a specific class in a bundle to go to a separate
> file. 
> 
> E.g. I have class 
> 
> /package com.myproject.mypackage;
> 
> public class MyClass {
>     private static final Logger logger =
> LoggerFactory.getLogger(MyClass.class);
>     ...    
> }/
> 
> 
> Everything that is logged from this class should go to a file MyClass.log.
> I've added a custom logger/appender to the default
> org.ops4j.pax.logging.cfg: 
> 
> /# MyClass logger
> log4j2.logger.myClass.name = com.myproject.mypackage.MyClass
> log4j2.logger.myClass.level = INFO
> log4j2.logger.myClass.additivity = false
> log4j2.logger.myClass.appenderRef.myClassAppender.ref = myClassAppender
> 
> # GatherStats appender
> log4j2.appender.myClassAppender.name = myClassAppender
> log4j2.appender.myClassAppender.type = RollingFile
> log4j2.appender.myClassAppender.fileName=${karaf.log}/MyClass.log
> log4j2.appender.myClassAppender.filePattern=${karaf.log}/MyClass.log-%d{yyyy-MM-dd-HH)-%i.log.gz
> 
> 
> I get the following stacktrace when launching Karaf: 
> 2019-04-17 12:05:28,948 CM Configuration Updater (ManagedService Update:
> pid=[org.ops4j.pax.logging]) ERROR The parameter is null: policy
> 2019-04-17 12:05:28,952 CM Configuration Updater (ManagedService Update:
> pid=[org.ops4j.pax.logging]) ERROR Unable to inject fields into builder
> class for plugin type class
> org.apache.logging.log4j.core.appender.RollingFileAppender, element
> RollingFile. org.apache.logging.log4j.core.config.ConfigurationException:
> Arguments given for element RollingFile are invalid
>         at
> org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.injectFields(PluginBuilder.java:198)
>         at
> org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:121)
>         at
> org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:952)
>         at
> org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:892)
>         at
> org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:884)
>         at
> org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:508)
>         at
> org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:232)
>         at
> org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:244)
>         at
> org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:545)
>         at
> org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:261)
>         at
> org.ops4j.pax.logging.log4j2.internal.PaxLoggingServiceImpl.doUpdate(PaxLoggingServiceImpl.java:213)
>         at
> org.ops4j.pax.logging.log4j2.internal.PaxLoggingServiceImpl.updated(PaxLoggingServiceImpl.java:158)
>         at
> org.ops4j.pax.logging.log4j2.internal.PaxLoggingServiceImpl$1ManagedPaxLoggingService.updated(PaxLoggingServiceImpl.java:426)
>         at
> org.apache.felix.cm.impl.helper.ManagedServiceTracker.updated(ManagedServiceTracker.java:189)
>         at
> org.apache.felix.cm.impl.helper.ManagedServiceTracker.updateService(ManagedServiceTracker.java:152)
>         at
> org.apache.felix.cm.impl.helper.ManagedServiceTracker.provideConfiguration(ManagedServiceTracker.java:85)
>         at
> org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.provide(ConfigurationManager.java:1113)
>         at
> org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.run(ConfigurationManager.java:1069)
>         at org.apache.felix.cm.impl.UpdateThread.run0(UpdateThread.java:138)
>         at org.apache.felix.cm.impl.UpdateThread.run(UpdateThread.java:105)
>         at java.lang.Thread.run(Thread.java:745)
> 
> 2019-04-17 12:05:28,953 CM Configuration Updater (ManagedService Update:
> pid=[org.ops4j.pax.logging]) ERROR Unable to invoke factory method in class
> class org.apache.logging.log4j.core.appender.RollingFileAppender for element
> RollingFile. java.lang.IllegalStateException: No factory method found for
> class org.apache.logging.log4j.core.appender.RollingFileAppender
>         at
> org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.findFactoryMethod(PluginBuilder.java:224)
>         at
> org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:130)
>         at
> org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:952)
>         at
> org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:892)
>         at
> org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:884)
>         at
> org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:508)
>         at
> org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:232)
>         at
> org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:244)
>         at
> org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:545)
>         at
> org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:261)
>         at
> org.ops4j.pax.logging.log4j2.internal.PaxLoggingServiceImpl.doUpdate(PaxLoggingServiceImpl.java:213)
>         at
> org.ops4j.pax.logging.log4j2.internal.PaxLoggingServiceImpl.updated(PaxLoggingServiceImpl.java:158)
>         at
> org.ops4j.pax.logging.log4j2.internal.PaxLoggingServiceImpl$1ManagedPaxLoggingService.updated(PaxLoggingServiceImpl.java:426)
>         at
> org.apache.felix.cm.impl.helper.ManagedServiceTracker.updated(ManagedServiceTracker.java:189)
>         at
> org.apache.felix.cm.impl.helper.ManagedServiceTracker.updateService(ManagedServiceTracker.java:152)
>         at
> org.apache.felix.cm.impl.helper.ManagedServiceTracker.provideConfiguration(ManagedServiceTracker.java:85)
>         at
> org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.provide(ConfigurationManager.java:1113)
>         at
> org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.run(ConfigurationManager.java:1069)
>         at org.apache.felix.cm.impl.UpdateThread.run0(UpdateThread.java:138)
>         at org.apache.felix.cm.impl.UpdateThread.run(UpdateThread.java:105)
>         at java.lang.Thread.run(Thread.java:745)
> 
> 2019-04-17 12:05:28,954 CM Configuration Updater (ManagedService Update:
> pid=[org.ops4j.pax.logging]) ERROR Null object returned for RollingFile in
> Appenders.
> 2019-04-17 12:05:28,954 CM Configuration Updater (ManagedService Update:
> pid=[org.ops4j.pax.logging]) ERROR Unable to locate appender
> "myClassAppender" for logger config "com.myproject.mypackage.MyClass"
> 
> 
> 
> --
> Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html
> 

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Mime
View raw message