You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Oli <ol...@postea.com> on 2011/03/28 15:27:02 UTC

Logging with ActiveMQ and Log4j

Hello.

I am currently developing a java project that is using ActiveMQ. I want to
capture the output from the ActiveMQ classes (e.g. the connector starting,
connections made and lost, messages sent and received) for logging purposes.
I am using Log4J as my logging tool in the application. 

I can not seem to find a way to capture the output and log it to file.
Adding log4j.properties to my project allows me to create a log file, but no
output is sent to the file.

This is my current log4j.properties file:

log4j.rootLogger=info, debug, logfile

# Or for more fine grained debug logging uncomment one of these
log4j.logger.org.apache.activemq=ALL
log4j.logger.org.apache.camel=ALL

# File appender
log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.file="My_directory"/logs/activemq.log
log4j.appender.logfile.maxFileSize=1024KB
log4j.appender.logfile.maxBackupIndex=5
log4j.appender.logfile.append=true
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d | %-5p | %m | %c | %t%n

Using this example, a log file is created (the activemq.log file), but
nothing gets written to it.

I am also using a Log4j Logger instance in my code for general logging,
which works fine.

Is there anything I need to do in code to "activate" the logging so it can
be written out to file? Are there any changes that I need to make to the
log4j.properties file?

I am using activemq v. 5.4.2 and log4j 1.2.16 and my project is in NetBeans.

Any help would be appreciated.

Oli

--
View this message in context: http://activemq.2283324.n4.nabble.com/Logging-with-ActiveMQ-and-Log4j-tp3411709p3411709.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Logging with ActiveMQ and Log4j

Posted by Oli <ol...@postea.com>.
Hi, thanks for the help.

I do think that "ALL" is a valid option.

I did find out what was the problem with my setup. The issue was that I did
not have the commons-logging jar in my project. Once I included that as a
library, the logging worked fine.

It was quite frustrating, since no error messages were displayed during
compile or runtime indicating that the .jar was needed and missing.

Oli

--
View this message in context: http://activemq.2283324.n4.nabble.com/Logging-with-ActiveMQ-and-Log4j-tp3411709p3414827.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Logging with ActiveMQ and Log4j

Posted by Gary Tully <ga...@gmail.com>.
> log4j: Handling log4j.additivity.org.apache.activemq=[null]
is a little odd.

Don't think ALL is a valid level, use TRACE instead, see:
http://logging.apache.org/log4j/1.2/manual.html

On 29 March 2011 11:32, Oli <ol...@postea.com> wrote:
> Hi. Thanks for the advice, but it still is not working.
>
> My activemq.log file gets created, but remains empty throughout the runtime
> of the application.
>
> Here is the output I get when I run the project with -Dlog4j.debug in the
> jvm start command:
>
> log4j: Trying to find [log4j.xml] using context classloader
> sun.misc.Launcher$AppClassLoader@11b86e7.
> log4j: Trying to find [log4j.xml] using
> sun.misc.Launcher$AppClassLoader@11b86e7 class loader.
> log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
> log4j: Trying to find [log4j.properties] using context classloader
> sun.misc.Launcher$AppClassLoader@11b86e7.
> log4j: Using URL [file:/MY_DIRECTORY/build/classes/log4j.properties] for
> automatic log4j configuration.
> log4j: Reading configuration from URL
> file:/MY_DIRECTORY/build/classes/log4j.properties
> log4j: Parsing for [root] with value=[INFO, logfile].
> log4j: Level token is [INFO].
> log4j: Category root set to INFO
> log4j: Parsing appender named "logfile".
> log4j: Parsing layout options for "logfile".
> log4j: Setting property [conversionPattern] to [%d [%-15.15t] %-5p
> %-30.30c{1} -].
> log4j: End of parsing for "logfile".
> log4j: Setting property [maxFileSize] to [1024KB].
> log4j: Setting property [append] to [true].
> log4j: Setting property [file] to [C:/OUTPUT_DIRECTORY/logs/activemq.log].
> log4j: Setting property [maxBackupIndex] to [5].
> log4j: setFile called: C:/OUTPUT_DIRECTORY/logs/activemq.log, true
> log4j: setFile ended
> log4j: Parsed "logfile" options.
> log4j: Parsing for [org.apache.activemq] with value=[INFO].
> log4j: Level token is [INFO].
> log4j: Category org.apache.activemq set to INFO
> log4j: Handling log4j.additivity.org.apache.activemq=[null]
> log4j: Parsing for [org.apache.activemq.spring] with value=[INFO].
> log4j: Level token is [INFO].
> log4j: Category org.apache.activemq.spring set to INFO
> log4j: Handling log4j.additivity.org.apache.activemq.spring=[null]
> log4j: Parsing for [org.springframework] with value=[INFO].
> log4j: Level token is [INFO].
> log4j: Category org.springframework set to INFO
> log4j: Handling log4j.additivity.org.springframework=[null]
> log4j: Parsing for [org.apache.xbean.spring] with value=[INFO].
> log4j: Level token is [INFO].
> log4j: Category org.apache.xbean.spring set to INFO
> log4j: Handling log4j.additivity.org.apache.xbean.spring=[null]
> log4j: Parsing for [org.apache.camel] with value=[INFO].
> log4j: Level token is [INFO].
> log4j: Category org.apache.camel set to INFO
> log4j: Handling log4j.additivity.org.apache.camel=[null]
> log4j: Parsing for [org.apache.activemq.transport.InactivityMonitor] with
> value=[INFO].
> log4j: Level token is [INFO].
> log4j: Category org.apache.activemq.transport.InactivityMonitor set to INFO
> log4j: Handling
> log4j.additivity.org.apache.activemq.transport.InactivityMonitor=[null]
> log4j: Finished configuring.
>
> However, this only provides me with logging that I am manually doing in the
> code, i.e. myLogger.error("").
>
> This does not log to file the output that is generated by the broker or any
> other general activemq output. Is there something that I need to to in code
> as well for this to be activated?
>
> Regards,
>
> Oli
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/Logging-with-ActiveMQ-and-Log4j-tp3411709p3414384.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>



-- 
http://blog.garytully.com
http://fusesource.com

Re: Logging with ActiveMQ and Log4j

Posted by Oli <ol...@postea.com>.
Hi. Thanks for the advice, but it still is not working.

My activemq.log file gets created, but remains empty throughout the runtime
of the application.

Here is the output I get when I run the project with -Dlog4j.debug in the
jvm start command:

log4j: Trying to find [log4j.xml] using context classloader
sun.misc.Launcher$AppClassLoader@11b86e7.
log4j: Trying to find [log4j.xml] using
sun.misc.Launcher$AppClassLoader@11b86e7 class loader.
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
log4j: Trying to find [log4j.properties] using context classloader
sun.misc.Launcher$AppClassLoader@11b86e7.
log4j: Using URL [file:/MY_DIRECTORY/build/classes/log4j.properties] for
automatic log4j configuration.
log4j: Reading configuration from URL
file:/MY_DIRECTORY/build/classes/log4j.properties
log4j: Parsing for [root] with value=[INFO, logfile].
log4j: Level token is [INFO].
log4j: Category root set to INFO
log4j: Parsing appender named "logfile".
log4j: Parsing layout options for "logfile".
log4j: Setting property [conversionPattern] to [%d [%-15.15t] %-5p
%-30.30c{1} -].
log4j: End of parsing for "logfile".
log4j: Setting property [maxFileSize] to [1024KB].
log4j: Setting property [append] to [true].
log4j: Setting property [file] to [C:/OUTPUT_DIRECTORY/logs/activemq.log].
log4j: Setting property [maxBackupIndex] to [5].
log4j: setFile called: C:/OUTPUT_DIRECTORY/logs/activemq.log, true
log4j: setFile ended
log4j: Parsed "logfile" options.
log4j: Parsing for [org.apache.activemq] with value=[INFO].
log4j: Level token is [INFO].
log4j: Category org.apache.activemq set to INFO
log4j: Handling log4j.additivity.org.apache.activemq=[null]
log4j: Parsing for [org.apache.activemq.spring] with value=[INFO].
log4j: Level token is [INFO].
log4j: Category org.apache.activemq.spring set to INFO
log4j: Handling log4j.additivity.org.apache.activemq.spring=[null]
log4j: Parsing for [org.springframework] with value=[INFO].
log4j: Level token is [INFO].
log4j: Category org.springframework set to INFO
log4j: Handling log4j.additivity.org.springframework=[null]
log4j: Parsing for [org.apache.xbean.spring] with value=[INFO].
log4j: Level token is [INFO].
log4j: Category org.apache.xbean.spring set to INFO
log4j: Handling log4j.additivity.org.apache.xbean.spring=[null]
log4j: Parsing for [org.apache.camel] with value=[INFO].
log4j: Level token is [INFO].
log4j: Category org.apache.camel set to INFO
log4j: Handling log4j.additivity.org.apache.camel=[null]
log4j: Parsing for [org.apache.activemq.transport.InactivityMonitor] with
value=[INFO].
log4j: Level token is [INFO].
log4j: Category org.apache.activemq.transport.InactivityMonitor set to INFO
log4j: Handling
log4j.additivity.org.apache.activemq.transport.InactivityMonitor=[null]
log4j: Finished configuring.

However, this only provides me with logging that I am manually doing in the
code, i.e. myLogger.error("").

This does not log to file the output that is generated by the broker or any
other general activemq output. Is there something that I need to to in code
as well for this to be activated?

Regards, 

Oli

--
View this message in context: http://activemq.2283324.n4.nabble.com/Logging-with-ActiveMQ-and-Log4j-tp3411709p3414384.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Logging with ActiveMQ and Log4j

Posted by Gary Tully <ga...@gmail.com>.
add -Dlog4j.debug to your jvm start command to see where log4j is
picking up its configuration. It may be that another properties file
is providing the log4j configuration.

On 28 March 2011 14:27, Oli <ol...@postea.com> wrote:
> Hello.
>
> I am currently developing a java project that is using ActiveMQ. I want to
> capture the output from the ActiveMQ classes (e.g. the connector starting,
> connections made and lost, messages sent and received) for logging purposes.
> I am using Log4J as my logging tool in the application.
>
> I can not seem to find a way to capture the output and log it to file.
> Adding log4j.properties to my project allows me to create a log file, but no
> output is sent to the file.
>
> This is my current log4j.properties file:
>
> log4j.rootLogger=info, debug, logfile
>
> # Or for more fine grained debug logging uncomment one of these
> log4j.logger.org.apache.activemq=ALL
> log4j.logger.org.apache.camel=ALL
>
> # File appender
> log4j.appender.logfile=org.apache.log4j.RollingFileAppender
> log4j.appender.logfile.file="My_directory"/logs/activemq.log
> log4j.appender.logfile.maxFileSize=1024KB
> log4j.appender.logfile.maxBackupIndex=5
> log4j.appender.logfile.append=true
> log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
> log4j.appender.logfile.layout.ConversionPattern=%d | %-5p | %m | %c | %t%n
>
> Using this example, a log file is created (the activemq.log file), but
> nothing gets written to it.
>
> I am also using a Log4j Logger instance in my code for general logging,
> which works fine.
>
> Is there anything I need to do in code to "activate" the logging so it can
> be written out to file? Are there any changes that I need to make to the
> log4j.properties file?
>
> I am using activemq v. 5.4.2 and log4j 1.2.16 and my project is in NetBeans.
>
> Any help would be appreciated.
>
> Oli
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/Logging-with-ActiveMQ-and-Log4j-tp3411709p3411709.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>



-- 
http://blog.garytully.com
http://fusesource.com