Skip to main content

Introduction

By default, ActiveMQ uses slf4j as an abstraction facade for various logging frameworks. Log4j is the default framework provided in ActiveMQ. In this article, we will cover how to quickly increase the logging information you can get from your broker in the most common scenarios using the provided out-of-the-box configuration.

Global Configuration

%ACTIVE_MQ_HOME%/conf/log4j.properties is the main file where you can update your broker logging configuration. By default, the root logger is the following:

[1]
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
log4j.logger.org.eclipse.jetty=WARN

# 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.RollingFileAppender
log4j.appender.logfile.file=${activemq.data}/activemq.log
log4j.appender.logfile.maxFileSize=1024KB
log4j.appender.logfile.maxBackupIndex=5
log4j.appender.logfile.append=true
log4j.appender.logfile.layout=org.apache.log4j.EnhancedPatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d | %-5p | %m | %c | %t%n%throwable{full}

Root Logger

The first line from [1] defines the root logger; the child definitions will inherit its level, appender, and ResourceBundle. The child application logging definition can define wider or narrower levels.  For example, if you want to enable debug level logging for the entire broker, you can:

Comment out:

# 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
# log4j.logger.org.eclipse.jetty=WARN

And uncomment the following line:

log4j.rootLogger=DEBUG, console, logfile

The above change will increase the broker login considerably in your File appender target to %ACTIVE_MQ_HOME%/data/activemq.log with DEBUG level messages. Notice the console appender will still be logging INFO level only information since it has the threshold set to INFO: og4j.appender.console.threshold=INFO

 

Child loggers for login connection data only

A common question ActiveMQ brokers administrators get is about consumer or producer connections. Enabling connection-only related data can be archived without setting DEBUG level on Root Logger.

To enable Transport and Connection related logging, you just need to add the following line to an out-of-the-box %ACTIVE_MQ_HOME%/conf/log4j.properties file:

log4j.logger.org.apache.activemq.broker.TransportConnection=DEBUG

The following is an example of log information generated when a producer (producer.superbiz.com) sends a message to the broker (192.168.1.5). You can now see specific information related to when the new connection and transport were set and stopped:

2022-09-12 13:07:36,309 | DEBUG | Setting up new connection id: ID:producer.superbiz.com-1:1, address: tcp://192.168.1.5:50461, info: ConnectionInfo {commandId = 1, responseRequired = true, connectionId = ID:producer.superbiz.com-1:1, clientId = ID:producer.superbiz.com-0:1, clientIp = null, userName = null, password = *****, brokerPath = null, brokerMasterConnector = false, manageable = true, clientMaster = true, faultTolerant = true, failoverReconnect = false} | org.apache.activemq.broker.TransportConnection | ActiveMQ Transport: tcp:///192.168.1.5:50461@61616
2022-09-12 13:07:36,371 | DEBUG | remove connection id: ID:producer.superbiz.com-1:1 | org.apache.activemq.broker.TransportConnection | ActiveMQ Transport: tcp:///192.168.1.5:50461@61616
2022-09-12 13:07:36,372 | DEBUG | Stopping connection: tcp://192.168.1.5:50461 | org.apache.activemq.broker.TransportConnection | ActiveMQ BrokerService[localhost] Task-7
2022-09-12 13:07:36,374 | DEBUG | Stopped transport: tcp://192.168.1.5:50461 | org.apache.activemq.broker.TransportConnection | ActiveMQ BrokerService[localhost] Task-7
2022-09-12 13:07:36,374 | DEBUG | Connection Stopped: tcp://192.168.1.5:50461 | org.apache.activemq.broker.TransportConnection | ActiveMQ BrokerService[localhost] Task-7

Similar data can be viewed temporarily in the ActiveMQ web console admin/network.jsp, but enabling broker Transport and Connection logging will persist the information in the activemq.log file for further analysis.

Live logging configuration Reload

The logging configuration is reloaded after each Broker restart. ActiveMQ documentation shows how to apply live reloading using JMX tools such as Jconsole. But in the cases when you don’t have a JMX setup at hand, an HTTP request to reload the logging configuration may be a better fit.

Since ActiveMQ 5.8.0, the Jolokia JMX-HTTP bridge is bundled by default. The following HTTP request provides live logging configuration reloading to an ActiveMQ broker, you may need to replace user, password, and broker URL accordingly.:

curl -H "Origin: http://localhost" -u user:password http://broker.foo.bar:8161/api/jolokia/exec/org.apache.activemq:type\=Broker,brokerName\=localhost,service\=Log4JConfiguration/reloadLog4jProperties

Successful reply by jolokia api indicating the logging configuration reload was successfull:

{"request":{"mbean":"org.apache.activemq:brokerName=localhost,service=Log4JConfiguration,type=Broker","type":"exec","operation":"reloadLog4jProperties"},"value":null,"timestamp":1663015107,"status":200}%

Audit logs

These logs provide you information about every management action done in your broker, either via JMX or Web Console management interface. Audit logs are disabled by default, but their configuration is arleady provided in %ACTIVE_MQ_HOME%/conf/log4j.properties file:

log4j.additivity.org.apache.activemq.audit=false
log4j.logger.org.apache.activemq.audit=INFO, audit
log4j.appender.audit=org.apache.log4j.RollingFileAppender
log4j.appender.audit.file=${activemq.data}/audit.log
log4j.appender.audit.maxFileSize=1024KB
log4j.appender.audit.maxBackupIndex=5
log4j.appender.audit.append=true
log4j.appender.audit.layout=org.apache.log4j.PatternLayout
log4j.appender.audit.layout.ConversionPattern=%-5p | %m | %t%n

To enable audit logs in your broker and have all the related information written in
%ACTIVE_MQ_HOME%/data/audit.log file, you need to uncomment the following line in %ACTIVE_MQ_HOME%/bin/env file:

ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS -Dorg.apache.activemq.audit=true"

The following is an example of the information available in the audit log as a result of a JMX logging property live reloading and a JMS queue purge called foo.bar:

INFO  | admin requested /admin/purgeDestination.action [JMSDestination='[queue:foo.bar]' JMSDestinationType='[queue]' secret='[daappkddb24j]' ] from  192.168.10.7 at 12-09-2022 15:06:55,590 | qtp1429483328-42
INFO  | anonymous called org.apache.activemq.broker.jmx.Log4JConfigView.reloadLog4jProperties[] on localhost at 12-09-2022 15:07:03,025 | qtp1429483328-36

Conclusion

Adjusting your ActiveMQ logging for monitoring, troubleshooting, or testing purposes is a straightforward process. For more fine-grain details on configuring log4j, you can check the official manual, for more information about ActiveMQ logging, check out the FAQ section.

Cesar Hernandez

Cesar Hernandez

César Hernández is a Senior Software Engineer at Tomitribe with experience in Enterprise Java Applications. He is a Java Champion, Duke's Choice Award winner, Eclipse Committer, Open Source advocate, teacher, and public speaker. When César is away from a computer, he enjoys spending time with his family, traveling and playing music with the Java Community Band, The Null Pointers. Follow Cesar on twitter @CesarHgt
CesarHgt

Leave a Reply