Questo contenuto non è disponibile nella lingua selezionata.
Chapter 19. Configuring 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 |
19.1. Changing the logging level Copia collegamentoCollegamento copiato negli appunti!
You can configure the logging level for each logger. 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.
Procedure
-
Open the
<broker_instance_dir>/etc/log4j2.propertiesconfiguration file. Add a
<logger name>.levelline after the logger name, as shown in the following example for theapache.activemq.artemis.core.serverlogger:logger.artemis_server.name=org.apache.activemq.artemis.core.server logger.artemis_server.level=INFO
logger.artemis_server.name=org.apache.activemq.artemis.core.server logger.artemis_server.level=INFOCopy to Clipboard Copied! Toggle word wrap Toggle overflow
19.2. Changing the logging layout format Copia collegamentoCollegamento copiato negli appunti!
You can change the default layout format for a log4j 2 appender from PatternLayout to JsonTemplateLayout. When an appender uses the JsonTemplateLayout format, log messages are created in JSON format.
Procedure
-
Open the
<broker_instance_dir>/etc/log4j2.propertiesconfiguration file. In a
appender<name>.layout.typeline, change the value fromPatternLayouttoJsonTemplateLayout. The following example shows the new format configured for thelog_fileappender.appender.log_file.layout.type = JsonTemplateLayout
appender.log_file.layout.type = JsonTemplateLayoutCopy to Clipboard Copied! Toggle word wrap Toggle overflow
19.3. Enabling audit logging Copia collegamentoCollegamento copiato negli appunti!
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.
Procedure
-
Open the
<broker_instance_dir>/etc/log4j2.propertiesconfiguration file. In a
logger.audit_<logger>.levelline, change the logging level toINFOfor each logger that you want to enable. For example, to enable the three available audit loggers, change the following lines toINFO:logger.audit_base.level = INFO logger.audit_resource.level = INFO logger.audit_message.level = INFO
logger.audit_base.level = INFO logger.audit_resource.level = INFO logger.audit_message.level = INFOCopy to Clipboard Copied! Toggle word wrap Toggle overflow
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.
19.4. Client or embedded server logging Copia collegamentoCollegamento copiato negli appunti!
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:
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
-Dlog4j2.configurationFile=file:///path/to/custom-log4j2-config.properties
The following is an example log4j2.properties file for a client:
19.5. AMQ Broker plugin support Copia collegamentoCollegamento copiato negli appunti!
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.
19.5.1. Adding plugins to the class path Copia collegamentoCollegamento copiato negli appunti!
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.
19.5.2. Registering a plugin Copia collegamentoCollegamento copiato negli appunti!
You must register a plugin by adding the broker-plugins element in the broker.xml configuration file. You can specify the plugin configuration value by 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.
19.5.3. Registering a plugin programmatically Copia collegamentoCollegamento copiato negli appunti!
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());
Configuration config = new ConfigurationImpl();
config.registerBrokerPlugin(new UserPlugin());
19.5.4. Logging specific events Copia collegamentoCollegamento copiato negli appunti!
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.
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.