Logging routes to separate files

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Logging routes to separate files

gemini
Hi,

I am using Apache Camel 2.10.1 which is inside ActiveMQ 5.7.
I have lot of routes and I want that every route has separate log file.
I found some info about "Sifting", but i doesn't work. Maybe I put wrong jar file into lib - "pax-logging-service-1.6.3.jar" from Apache ServiceMix 4.4.2.
I am not Java programmer - just want do some integration with Camel & ActiveMQ, so please explain how to configure logging and give some example.

I try following "log4j.properties", but I get error on the bottom:
----------------------------------------------------------------------------------------
log4j.rootLogger=INFO, console, logfile
log4j.logger.org.apache.activemq.spring=WARN
log4j.logger.org.apache.activemq.web.handler=WARN
log4j.logger.org.springframework=WARN
log4j.logger.org.apache.xbean=WARN
log4j.logger.org.apache.camel=INFO

# Console appender
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%5p | %m%n
log4j.appender.console.threshold=INFO

# File appender
log4j.appender.logfile=org.apache.log4j.sift.MDCSiftingAppender
log4j.appender.logfile.key=camel.routeId
log4j.appender.logfile.default=camel
log4j.appender.logfile.appender=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.appender.MaxFileSize=20MB
log4j.appender.logfile.appender.MaxBackupIndex=5
log4j.appender.logfile.appender.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.appender.layout.ConversionPattern=%d | %-5p | %m | %c | %t%n
log4j.appender.logfile.appender.file=${activemq.base}/data/$\\{camel.routeId\\}.log
log4j.appender.logfile.appender.append=true
log4j.appender.logfile.threshold=TRACE
----------------------------------------------------------------------------------------


SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/esb/activemq/lib/optional/slf4j-log4j12-1.6.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/esb/activemq/lib/slf4j-log4j12-1.6.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
log4j:WARN Failed to set property [appender] to value "org.apache.log4j.RollingFileAppender".
 INFO | Refreshing org.apache.activemq.xbean.XBeanBrokerFactory$1@5488e2dd: startup date [Wed Nov 14 18:04:44 CET 2012]; root of context hierarchy
ERROR: java.lang.RuntimeException: Failed to execute start task. Reason: java.lang.NullPointerException
java.lang.RuntimeException: Failed to execute start task. Reason: java.lang.NullPointerException
        at org.apache.activemq.console.command.StartCommand.runTask(StartCommand.java:98)
        at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:57)
        at org.apache.activemq.console.command.ShellCommand.runTask(ShellCommand.java:148)
        at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:57)
        at org.apache.activemq.console.command.ShellCommand.main(ShellCommand.java:90)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.activemq.console.Main.runTaskClass(Main.java:257)
        at org.apache.activemq.console.Main.main(Main.java:111)
Caused by: java.lang.NullPointerException
        at org.apache.log4j.sift.MDCSiftingAppender.getAppender(MDCSiftingAppender.java:109)
        at org.apache.log4j.sift.MDCSiftingAppender.append(MDCSiftingAppender.java:79)
        at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
        at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
        at org.apache.log4j.Category.callAppenders(Category.java:206)
        at org.apache.log4j.Category.forcedLog(Category.java:391)
        at org.apache.log4j.Category.log(Category.java:856)
        at org.slf4j.impl.Log4jLoggerAdapter.log(Log4jLoggerAdapter.java:602)
        at org.apache.commons.logging.impl.SLF4JLocationAwareLog.info(SLF4JLocationAwareLog.java:159)
        at org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:456)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:394)
        at org.apache.xbean.spring.context.ResourceXmlApplicationContext.<init>(ResourceXmlApplicationContext.java:64)
        at org.apache.xbean.spring.context.ResourceXmlApplicationContext.<init>(ResourceXmlApplicationContext.java:52)
        at org.apache.activemq.xbean.XBeanBrokerFactory$1.<init>(XBeanBrokerFactory.java:102)
        at org.apache.activemq.xbean.XBeanBrokerFactory.createApplicationContext(XBeanBrokerFactory.java:102)
        at org.apache.activemq.xbean.XBeanBrokerFactory.createBroker(XBeanBrokerFactory.java:66)
        at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:71)
        at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:54)
        at org.apache.activemq.console.command.StartCommand.startBroker(StartCommand.java:115)
        at org.apache.activemq.console.command.StartCommand.runTask(StartCommand.java:74)
        ... 10 more
Reply | Threaded
Open this post in threaded view
|

Re: Logging routes to separate files

Christian Mueller
Administrator
The error message tells you, that "slf4j-log4j12-1.6.6.jar" is found in two
places. Remove one.
You don't need the "pax-logging-service-1.6.3.jar". It's only needed in an
OSGI environment.
And checkout [1] on how to configure log4j.

[1] http://logging.apache.org/log4j/1.2/

Best,
Christian

On Wed, Nov 14, 2012 at 11:55 PM, gemini <[hidden email]> wrote:

> Hi,
>
> I am using Apache Camel 2.10.1 which is inside ActiveMQ 5.7.
> I have lot of routes and I want that every route has separate log file.
> I found some info about "Sifting", but i doesn't work. Maybe I put wrong
> jar
> file into lib - "pax-logging-service-1.6.3.jar" from Apache ServiceMix
> 4.4.2.
> I am not Java programmer - just want do some integration with Camel &
> ActiveMQ, so please explain how to configure logging and give some example.
>
> I try following "log4j.properties", but I get error on the bottom:
>
> ----------------------------------------------------------------------------------------
> log4j.rootLogger=INFO, console, logfile
> log4j.logger.org.apache.activemq.spring=WARN
> log4j.logger.org.apache.activemq.web.handler=WARN
> log4j.logger.org.springframework=WARN
> log4j.logger.org.apache.xbean=WARN
> log4j.logger.org.apache.camel=INFO
>
> # Console appender
> log4j.appender.console=org.apache.log4j.ConsoleAppender
> log4j.appender.console.layout=org.apache.log4j.PatternLayout
> log4j.appender.console.layout.ConversionPattern=%5p | %m%n
> log4j.appender.console.threshold=INFO
>
> # File appender
> log4j.appender.logfile=org.apache.log4j.sift.MDCSiftingAppender
> log4j.appender.logfile.key=camel.routeId
> log4j.appender.logfile.default=camel
> log4j.appender.logfile.appender=org.apache.log4j.RollingFileAppender
> log4j.appender.logfile.appender.MaxFileSize=20MB
> log4j.appender.logfile.appender.MaxBackupIndex=5
> log4j.appender.logfile.appender.layout=org.apache.log4j.PatternLayout
> log4j.appender.logfile.appender.layout.ConversionPattern=%d | %-5p | %m |
> %c
> | %t%n
>
> log4j.appender.logfile.appender.file=${activemq.base}/data/$\\{camel.routeId\\}.log
> log4j.appender.logfile.appender.append=true
> log4j.appender.logfile.threshold=TRACE
>
> ----------------------------------------------------------------------------------------
>
>
> SLF4J: Class path contains multiple SLF4J bindings.
> SLF4J: Found binding in
>
> [jar:file:/home/esb/activemq/lib/optional/slf4j-log4j12-1.6.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
> SLF4J: Found binding in
>
> [jar:file:/home/esb/activemq/lib/slf4j-log4j12-1.6.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
> SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an
> explanation.
> SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
> log4j:WARN Failed to set property [appender] to value
> "org.apache.log4j.RollingFileAppender".
>  INFO | Refreshing org.apache.activemq.xbean.XBeanBrokerFactory$1@5488e2dd
> :
> startup date [Wed Nov 14 18:04:44 CET 2012]; root of context hierarchy
> ERROR: java.lang.RuntimeException: Failed to execute start task. Reason:
> java.lang.NullPointerException
> java.lang.RuntimeException: Failed to execute start task. Reason:
> java.lang.NullPointerException
>         at
>
> org.apache.activemq.console.command.StartCommand.runTask(StartCommand.java:98)
>         at
>
> org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:57)
>         at
>
> org.apache.activemq.console.command.ShellCommand.runTask(ShellCommand.java:148)
>         at
>
> org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:57)
>         at
> org.apache.activemq.console.command.ShellCommand.main(ShellCommand.java:90)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at
>
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>         at
>
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:597)
>         at org.apache.activemq.console.Main.runTaskClass(Main.java:257)
>         at org.apache.activemq.console.Main.main(Main.java:111)
> Caused by: java.lang.NullPointerException
>         at
>
> org.apache.log4j.sift.MDCSiftingAppender.getAppender(MDCSiftingAppender.java:109)
>         at
> org.apache.log4j.sift.MDCSiftingAppender.append(MDCSiftingAppender.java:79)
>         at
> org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
>         at
>
> org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
>         at org.apache.log4j.Category.callAppenders(Category.java:206)
>         at org.apache.log4j.Category.forcedLog(Category.java:391)
>         at org.apache.log4j.Category.log(Category.java:856)
>         at
> org.slf4j.impl.Log4jLoggerAdapter.log(Log4jLoggerAdapter.java:602)
>         at
> org.apache.commons.logging.impl.SLF4JLocationAwareLog.info
> (SLF4JLocationAwareLog.java:159)
>         at
>
> org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:456)
>         at
>
> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:394)
>         at
>
> org.apache.xbean.spring.context.ResourceXmlApplicationContext.<init>(ResourceXmlApplicationContext.java:64)
>         at
>
> org.apache.xbean.spring.context.ResourceXmlApplicationContext.<init>(ResourceXmlApplicationContext.java:52)
>         at
>
> org.apache.activemq.xbean.XBeanBrokerFactory$1.<init>(XBeanBrokerFactory.java:102)
>         at
>
> org.apache.activemq.xbean.XBeanBrokerFactory.createApplicationContext(XBeanBrokerFactory.java:102)
>         at
>
> org.apache.activemq.xbean.XBeanBrokerFactory.createBroker(XBeanBrokerFactory.java:66)
>         at
>
> org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:71)
>         at
>
> org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:54)
>         at
>
> org.apache.activemq.console.command.StartCommand.startBroker(StartCommand.java:115)
>         at
>
> org.apache.activemq.console.command.StartCommand.runTask(StartCommand.java:74)
>         ... 10 more
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Logging-routes-to-separate-files-tp5722752.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



--
Reply | Threaded
Open this post in threaded view
|

Re: Logging routes to separate files

gemini
Thank you for response.
I found out different way to achieve my goal - I switch to another logging framework - Logback.
With this new logging kit everything was pretty simple.

Earlier I didn't realize, that change logging kit is so simple when using slf4j - I just remove "log4j" and "slf4j-log4j12" jar's, downloaded Logback 1.0.7 (current version), and put jars logback-core and logback-classic into lib directory. After that, everything just started to work.

Configuration of sifting was simple - just created "logback.xml" in conf directory (in classpath) based on manual and it started working.

I could even use properties translator - http://logback.qos.ch/translator/