Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 18. Logging
AMQ Broker uses the Apache Log4j 2 logging utility to provide message logging. When you install a broker, it has a default Log4j 2 configuration in the <broker_instance_dir>/etc/log4j2.properties
file. With the default configuration, the loggers write to both the console and to a file.
The loggers available in AMQ Broker are shown in the following table.
Logger | Description |
---|---|
org.apache.activemq.artemis.core.server | Logs the broker core |
org.apache.activemq.artemis.journal | Logs Journal calls |
org.apache.activemq.artemis.utils | Logs utility calls |
org.apache.activemq.artemis.jms | Logs JMS calls |
org.apache.activemq.artemis.integration.bootstrap | Logs bootstrap calls |
org.apache.activemq.audit.base | Logs access to all JMX object methods |
org.apache.activemq.audit.message | Logs message operations such as production, consumption, and browsing of messages |
org.apache.activemq.audit.resource | Logs authentication events, creation or deletion of broker resources from JMX or the AMQ Broker management console, and browsing of messages in the management console |
18.1. Changing the logging level
You can configure the logging level for each logger in the <logger name>.level
line after the logger name, as shown in the following example for the apache.activemq.artemis.core.server
logger:
logger.artemis_server.name=org.apache.activemq.artemis.core.server logger.artemis_server.level=INFO
The default logging level for audit loggers is OFF
, which means that logging is disabled. The default logging level for the other loggers available in AMQ Broker is INFO
. For information on the logging levels available in Log4j 2, see the Log4j 2 documentation.
18.2. Enabling audit logging
Three audit loggers are available for you to enable; a base audit logger, a message audit logger, and a resource audit logger.
- Base audit logger (org.apache.activemq.audit.base)
- Logs access to all JMX object methods, such as creation and deletion of addresses and queues. The log does not indicate whether these operations succeeded or failed.
- Message audit logger (org.apache.activemq.audit.message)
- Logs message-related broker operations, such as production, consumption, or browsing of messages.
- Resource audit logger (org.apache.activemq.audit.resource)
- Logs authentication success or failure from clients, routes, and the AMQ Broker management console. Also logs creation, update, or deletion of queues from either JMX or the management console, and browsing of messages in the management console.
You can enable each audit logger independently of the others. By default, the logging level is set to OFF
, which means logging is disabled, for each audit logger. To enable one of the audit loggers, change the logging level from OFF
to INFO
. For example:
logger.audit_base = INFO, audit_log_file
INFO
is the only available logging level for the logger.org.apache.activemq.audit.base
, logger.org.apache.activemq.audit.message
, and logger.org.apache.activemq.audit.resource
audit loggers.
The message audit logger runs on a performance-intensive path on the broker. Enabling the logger might negatively affect the performance of the broker, particularly if the broker is running under a high messaging load. Red Hat recommends that you do not enable audit logging on messaging systems where high throughput is required.
18.3. Client or embedded server logging
If you want to enable logging on a client, you need to include a logging implementation in your application that supports the SLF4J facade. If you are using Maven, add the following dependencies for Log4j 2:
<dependency> <groupId>org.apache.activemq</groupId> <artifactId>artemis-jms-client</artifactId> <version>2.28.0</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j-impl</artifactId> <version>2.19.0</version> </dependency>
You can supply the Log4j 2 configuration in a log4j2.properties
file in the classpath. Or, you can specify a custom configuration file by using the log4j2.configurationFile
system property. For example:
-Dlog4j2.configurationFile=file:///path/to/custom-log4j2-config.properties
The following is an example log4j2.properties
file for a client:
# Log4J 2 configuration # Monitor config file every X seconds for updates monitorInterval = 5 rootLogger = INFO, console, log_file logger.activemq.name=org.apache.activemq logger.activemq.level=INFO # Console appender appender.console.type=Console appender.console.name=console appender.console.layout.type=PatternLayout appender.console.layout.pattern=%d %-5level [%logger] %msg%n # Log file appender appender.log_file.type = RollingFile appender.log_file.name = log_file appender.log_file.fileName = log/application.log appender.log_file.filePattern = log/application.log.%d{yyyy-MM-dd} appender.log_file.layout.type = PatternLayout appender.log_file.layout.pattern = %d %-5level [%logger] %msg%n appender.log_file.policies.type = Policies appender.log_file.policies.cron.type = CronTriggeringPolicy appender.log_file.policies.cron.schedule = 0 0 0 * * ? appender.log_file.policies.cron.evaluateOnStartup = true
18.4. AMQ Broker plugin support
AMQ supports custom plugins. You can use plugins to log information about many different types of events that would otherwise only be available through debug logs. Multiple plugins can be registered, tied, and executed together. The plugins are executed based on the order of the registration, that is, the first plugin registered is always executed first.
You can create custom plugins and implement them using the ActiveMQServerPlugin
interface. This interface ensures that the plugin is on the classpath, and is registered with the broker. As all the interface methods are implemented by default, you have to add only the required behavior that needs to be implemented.
18.4.1. Adding plugins to the class path
Add the custom created broker plugins to the broker runtime by adding the relevant .jar
files to the <broker_instance_dir>/lib
directory.
If you are using an embedded system, place the .jar
file under the regular class path of your embedded application.
18.4.2. Registering a plugin
You must register a plugin by adding the broker-plugins
element in the broker.xml
configuration file. You can specify the plugin configuration value using the property
child elements. These properties are read and passed into the plugin’s init (Map<String, String>) operation after the plugin has been instantiated.
<broker-plugins> <broker-plugin class-name="some.plugin.UserPlugin"> <property key="property1" value="val_1" /> <property key="property2" value="val_2" /> </broker-plugin> </broker-plugins>
18.4.3. Registering a plugin programmatically
To register a plugin programmatically, use the registerBrokerPlugin()
method and pass in a new instance of your plugin. The example below shows the registration of the UserPlugin
plugin:
Configuration config = new ConfigurationImpl();
config.registerBrokerPlugin(new UserPlugin());
18.4.4. Logging specific events
By default, AMQ broker provides the LoggingActiveMQServerPlugin
plugin to log specific broker events. The LoggingActiveMQServerplugin
plugin is commented-out by default and does not log any information.
The following table describes each plugin property. Set a configuration property value to true
to log events.
Property | Description |
| Logs information when a connection is created or destroyed. |
| Logs information when a session is created or closed. |
| Logs information when a consumer is created or closed. |
| Logs information when message is delivered to a consumer and when a message is acknowledged by a consumer. |
| Logs information when a message has been sent to an address and when a message has been routed within the broker. |
| Logs information when a queue created or destroyed, when a message is expired, when a bridge is deployed, and when a critical failure occurs. |
| Logs information for all the above events. |
To configure the LoggingActiveMQServerPlugin
plugin to log connection events, uncomment the <broker-plugins>
section in the broker.xml
configuration file. The value of all the events is set to true
in the commented default example.
<configuration ...> ... <!-- Uncomment the following if you want to use the Standard LoggingActiveMQServerPlugin plugin to log in events --> <broker-plugins> <broker-plugin class-name="org.apache.activemq.artemis.core.server.plugin.impl.LoggingActiveMQServerPlugin"> <property key="LOG_ALL_EVENTS" value="true"/> <property key="LOG_CONNECTION_EVENTS" value="true"/> <property key="LOG_SESSION_EVENTS" value="true"/> <property key="LOG_CONSUMER_EVENTS" value="true"/> <property key="LOG_DELIVERING_EVENTS" value="true"/> <property key="LOG_SENDING_EVENTS" value="true"/> <property key="LOG_INTERNAL_EVENTS" value="true"/> </broker-plugin> </broker-plugins> ... </configuration>
When you change the configuration parameters inside the <broker-plugins>
section, you must restart the broker to reload the configuration updates. These configuration changes are not reloaded based on the configuration-file-refresh-period
setting.
When the log level is set to INFO
, an entry is logged after the event has occurred. If the log level is set to DEBUG
, log entries are generated for both before and after the event, for example, beforeCreateConsumer()
and afterCreateConsumer()
. If the log Level is set to DEBUG
, the logger logs more information for a notification, when available.