如何更改日志记录
常见问题解答 > 使用 Apache ActiveMQ Classic > 如何更改日志记录
如何更改日志记录
我们使用 slf4j 在代理客户端和代理本身记录信息,因此您可以完全配置使用哪些日志记录级别以及是否将日志记录到文件或控制台等。有关更多信息,请参阅log4j 手册.
您可以通过编辑 conf/log4j.properties 文件来禁用 ActiveMQ Classic 日志记录,以禁用对 activemq 的所有 INFO 级别日志记录,方法是添加以下行
log4j.logger.org.apache.activemq=WARN
或要完全禁用 stdout 日志记录,请更改此行
log4j.rootLogger=INFO, stdout, out
为
log4j.rootLogger=INFO, out
如何在运行时更改日志记录?
ActiveMQ Classic 中的默认日志记录级别为 INFO。这可以通过在终端中启动默认的 ActiveMQ Classic 二进制文件来查看。这样做,您将看到下面显示的输出
$ ./bin/activemq
ACTIVEMQ_HOME: /Users/bsnyder/amq/apache-activemq-5.1.0
ACTIVEMQ_BASE: /Users/bsnyder/amq/apache-activemq-5.1.0
Loading message broker from: xbean:activemq.xml
INFO BrokerService - Using Persistence Adapter: AMQPersistenceAdapter(/Users/bsnyder/amq/apache-activemq-5.1.0/data)
INFO BrokerService - ActiveMQ 5.1.0 JMS Message Broker (localhost) is starting
INFO BrokerService - For help or more information please see: https://activemq.apache.org/
INFO AMQPersistenceAdapter - AMQStore starting using directory: /Users/bsnyder/amq/apache-activemq-5.1.0/data
INFO KahaStore - Kaha Store using data directory /Users/bsnyder/amq/apache-activemq-5.1.0/data/kr-store/state
INFO AMQPersistenceAdapter - Active data files: []
INFO KahaStore - Kaha Store using data directory /Users/bsnyder/amq/apache-activemq-5.1.0/data/kr-store/data
INFO TransportServerThreadSupport - Listening for connections at: tcp://mongoose.local:61616
INFO TransportConnector - Connector openwire Started
INFO TransportServerThreadSupport - Listening for connections at: ssl://mongoose.local:61617
INFO TransportConnector - Connector ssl Started
INFO TransportServerThreadSupport - Listening for connections at: stomp://mongoose.local:61613
INFO TransportConnector - Connector stomp Started
INFO TransportServerThreadSupport - Listening for connections at: xmpp://mongoose.local:61222
INFO TransportConnector - Connector xmpp Started
INFO NetworkConnector - Network Connector default-nc Started
INFO BrokerService - ActiveMQ JMS Message Broker (localhost, ID:mongoose.local-56138-1224025139259-0:0) started
INFO log - Logging to org.slf4j.impl.JCLLoggerAdapter(org.mortbay.log) via org.mortbay.log.Slf4jLog
INFO log - jetty-6.1.9
INFO WebConsoleStarter - ActiveMQ WebConsole initialized.
INFO /admin - Initializing Spring FrameworkServlet 'dispatcher'
INFO log - ActiveMQ Console at http://0.0.0.0:8161/admin
INFO log - ActiveMQ Web Demos at http://0.0.0.0:8161/demo
INFO log - RESTful file access application at http://0.0.0.0:8161/fileserver
INFO log - Started [email protected]:8161
INFO FailoverTransport - Successfully connected to tcp://127.0.0.1:61616
但是,停止 ActiveMQ Classic 来更改日志记录级别并不总是可行的。在许多情况下,日志记录级别和其他配置详细信息可能需要在运行时更改。使用诸如 jconsole 之类的 JMX 工具,可以更改日志记录配置文件并在不关闭 ActiveMQ Classic 的情况下重新加载它。
要将 ActiveMQ Classic 日志记录级别从 INFO 更改为 DEBUG,同时 ActiveMQ Classic 正在运行,请启动 jconsole,指向 ActiveMQ Classic 实例,然后导航到代理对象的“操作”选项卡,如下所示
要在 ActiveMQ Classic 中启用调试级别日志记录,请编辑 ActiveMQ Classic 二进制分发版中包含的 conf/log4j.properties
文件,以禁用 INFO 级别日志记录并从以下内容启用 DEBUG 级别日志记录
log4j.rootLogger=INFO, stdout, out
log4j.logger.org.apache.activemq.spring=WARN
log4j.logger.org.springframework=WARN
log4j.logger.org.apache.xbean.spring=WARN
# When debugging or reporting problems to the ActiveMQ team,
# comment out the above lines and uncomment the next.
#log4j.rootLogger=DEBUG, out, stdout
为此
#log4j.rootLogger=INFO, stdout, out
log4j.logger.org.apache.activemq.spring=WARN
log4j.logger.org.springframework=WARN
log4j.logger.org.apache.xbean.spring=WARN
# When debugging or reporting problems to the ActiveMQ team,
# comment out the above lines and uncomment the next.
log4j.rootLogger=DEBUG, out, stdout
请注意,行 log4j.rootLogger=INFO, stdout, out
已被注释掉,而行 log4j.rootLogger=DEBUG, out, stdout
已被取消注释。保存此更改,然后在 jconsole 中单击名为 reloadLog4jProperties 的按钮,如下所示
单击 reloadLog4jProperties 按钮后,会弹出一个对话框,提示“方法已成功调用”。这只是让您知道已调用 reloadLog4jProperties
方法以重新加载 conf/log4j.properties
文件。现在请注意,在 ActiveMQ Classic 正在运行的终端中,正在输出的日志记录现在为 DEBUG
INFO WebConsoleStarter - ActiveMQ WebConsole initialized.
INFO /admin - Initializing Spring FrameworkServlet 'dispatcher'
INFO log - ActiveMQ Console at http://0.0.0.0:8161/admin
INFO log - ActiveMQ Web Demos at http://0.0.0.0:8161/demo
INFO log - RESTful file access application at http://0.0.0.0:8161/fileserver
INFO log - Started [email protected]:8161
INFO FailoverTransport - Successfully connected to tcp://127.0.0.1:61616
DEBUG InactivityMonitor - 10000 ms elapsed since last write check.
DEBUG InactivityMonitor - 10000 ms elapsed since last write check.
DEBUG AbstractRegion - Removing consumer: ID:mongoose.local-56517-1224026019987-0:0:-1:1
DEBUG AbstractRegion - Removing consumer: ID:mongoose.local-56511-1224026011897-0:0:1:1
DEBUG TransportConnection - Stopping connection: /127.0.0.1:56518
DEBUG TcpTransport - Stopping transport tcp:///127.0.0.1:56518
DEBUG TransportConnection - Stopped connection: /127.0.0.1:56518
DEBUG TransportConnection - Connection Stopped: /127.0.0.1:56518
DEBUG AbstractRegion - Removing consumer: ID:mongoose.local-56511-1224026011897-0:0:-1:1
DEBUG TransportConnection - Stopping connection: /127.0.0.1:56512
DEBUG TcpTransport - Stopping transport tcp:///127.0.0.1:56512
DEBUG TransportConnection - Stopped connection: /127.0.0.1:56512
DEBUG TransportConnection - Connection Stopped: /127.0.0.1:56512
DEBUG InactivityMonitor - 9999 ms elapsed since last write check.
DEBUG InactivityMonitor - 10000 ms elapsed since last write check.
DEBUG InactivityMonitor - 29999 ms elapsed since last read check.
禁用 DEBUG
级别日志记录并启用 INFO
级别日志记录是通过编辑 log4j.properties
文件并再次单击 reloadLog4jProperties 按钮来完成的。