You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级ActiveMQ Classic至5.18.6后Log4J配置文件未生效的技术求助

升级ActiveMQ Classic至5.18.6后Log4J配置文件未生效的技术求助

我最近在将ActiveMQ Classic的activemq-all-version.jar从5.16.0版本升级到5.18.6,结果遇到了Log4J日志格式完全不符合预期的问题,折腾了好一阵子没找到根源,来求助各位大佬。

之前的正常表现

升级前,我的应用基于Log4J 2.17相关依赖(主要是log4j-1.2-api-2.17.1.jar)输出日志,log4j.properties里的配置如下:

log4j.appender.defaultAppender.layout.ConversionPattern=[%d{yy-MM-dd HH:mm:ss.SSS}] %20C{3}:%L [%-6.6p] => %m%N

对应的日志输出格式完全符合预期,示例如下:

[25-01-10 12:34:56.789] utils.socket.SocketStream$SocketWorker:515 [INFO  ] => SMD-0: Testing for connection

升级后的异常情况

升级到5.18.6版本后,我没有修改任何配置文件或业务代码,但日志输出完全忽略了我指定的格式,变成了极简的样式:

INFO | SMD-0: Testing for connection
ERROR | SMD-0: The OutputStream is null

更奇怪的是,我尝试修改Log4J配置里的日志文件路径(比如log4j.appender...File相关配置),结果日志文件名根本没有变化。后来我发现,应用作为服务运行时,启动脚本的输出重定向在控制日志的存储位置,但我的代码全都是用Log4j的Logger类来打日志的,按道理应该还是走Log4J的配置才对,现在感觉ActiveMQ好像完全忽略了我的Log4J配置,在用默认的控制台输出格式。

我尝试过的解决步骤

后来我猜测可能是Log4J 2的配置格式问题,于是做了如下修改:

  1. 把应用config.properties里的log4j.configuration=${config_dir}/log4j.properties改成了${config_dir}/log4j2.properties
  2. 新的log4j2.properties配置内容如下(省略了注释和空行):
name=PropertiesConfig
rootLogger.level=DEBUG
rootLogger.appenderRef.stdout.ref=STDOUT
rootLogger.appenderRef.logfile.ref=logfile
log4j.appender.defaultAppender.File=${log_dir}/app.log
appender.stdout.type=Console
appender.stdout.name=STDOUT
appender.stdout.layout.type=PatternLayout
appender.stdout.layout.pattern=[%d{yy-MM-dd HH:mm:ss.SSS}] %20C{3}:%L [%-6.6p] => %m%n
appender.stdout.filter.threshold.type=ThresholdFilter
appender.stdout.filter.threshold.level=debug
appender.logfile.type=File
appender.logfile.name=logfile
appender.logfile.fileName={log_dir}/logfile.log
appender.logfile.layout.type=PatternLayout
appender.logfile.layout.pattern=[%d{yy-MM-dd HH:mm:ss.SSS}] %20C{3}:%L [%-6.6p] => %m%n
appender.logfile.filter.threshold.type=ThresholdFilter
appender.logfile.filter.threshold.level=debug

但修改后问题依然存在——日志依然只输出到stdout,完全没有使用我指定的格式,而且logfile.log文件根本没有被创建过。

另外补充下:为什么我们使用activemq-all.jar而不是单独的依赖包?因为我们只能访问私有仓库,里面没有ActiveMQ的拆分依赖,也没办法访问公共Maven仓库。

备注:内容来源于stack exchange,提问作者Codes with Hammer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 09:34:51