如何覆盖 Maven 插件的 log4j 配置?

发布于 2024-10-08 23:00:30 字数 2414 浏览 0 评论 0原文

我正在使用 Cargo Maven 插件将 WAR 部署到远程服务器,但遇到了问题。我可能会针对该问题创建第二个问题,但这一个问题是关于覆盖 Maven 插件的 log4j 配置。 Cargo 使用 JBoss 的客户端库将内容发送到 JBoss 服务器(我正在尝试这样做)。JBoss 库使用 log4j。据我所知,Cargo 没有设置任何类型的映射层。

因此,本质上,日志消息发生在 Maven 插件的依赖库中。我尝试设置 -Dlog4j.debug 并得到以下信息:

log4j:尝试使用 ClassRealm[plugin>org.codehaus.cargo:cargo-maven2-plugin:1.0.5,父项:ClassRealm[maven.api,父项:null]] 查找 [log4j.xml]类加载器。
log4j:尝试使用 ClassLoader.getSystemResource() 查找 [log4j.xml]。
log4j:尝试使用上下文类加载器 ClassRealm[plugin>org.codehaus.cargo:cargo-maven2-plugin:1.0.5,父级:ClassRealm[maven.api,父级:null]] 查找 [log4j.properties]。
log4j:使用 URL [jar:file:/C:/Users/username/.m2/repository/org/jboss/jbossts/jbossjts/4.13.1.Final/jbossjts-4.13.1.Final.jar!/log4j.properties ] 用于自动 log4j 配置。
log4j:从 URL jar:file:/C:/Users/username/.m2/repository/org/jboss/jbossts/jbossjts/4.13.1.Final/jbossjts-4.13.1.Final.jar!/log4j 读取配置。特性
log4j:找不到根记录器信息。这样可以吗?
log4j:解析 [com.arjuna],值为 [INFO,默认值,stdout]。
log4j:级别标记是[INFO]。
log4j:类别 com.arjuna 设置为 INFO
log4j:解析名为“default”的附加程序。
log4j:解析“默认”布局选项。
log4j:将属性 [conversionPattern] 设置为 [%d [%t] %-5p %c - %m%n]。
log4j:“默认”解析结束。
log4j:将属性 [maxBackupIndex] 设置为 [2]。
log4j:将属性 [file] 设置为 [transaction.log]。
log4j:将属性 [maxFileSize] 设置为 [500KB]。
log4j:setFile 调用:transaction.log,true
log4j:setFile 结束
log4j:解析“默认”选项。
log4j:解析名为“stdout”的附加程序。
log4j:解析“stdout”的布局选项。
log4j:将属性 [conversionPattern] 设置为 [%d [%t] %-5p %c - %m%n]。
log4j:“stdout”的解析结束。
log4j:将属性 [threshold] 设置为 [WARN]。
log4j:解析的“stdout”选项。
log4j:处理 log4j.additivity.com.arjuna=[null]
log4j:配置完成。
log4j:WARN 找不到记录器 (org.jnp.interfaces.TimedSocketFactory) 的附加程序。
log4j:WARN 请正确初始化 log4j 系统。

然后我尝试设置 -Dlog4j.configuration=mylog4j.properties 但得到了这个:

log4j:尝试使用上下文类加载器 ClassRealm[plugin>org.codehaus.cargo:cargo-maven2-plugin:1.0.5,父级:ClassRealm[maven.api,父级:null] 查找 [mylog4j.properties] ]]。
log4j:尝试使用 ClassRealm[plugin>org.codehaus.cargo:cargo-maven2-plugin:1.0.5,parent: ClassRealm[maven.api,parent: null]] 类加载器查找 [mylog4j.properties]。
log4j:尝试使用 ClassLoader.getSystemResource() 查找 [mylog4j.properties]。
log4j:找不到资源:[mylog4j.properties]。
log4j:WARN 找不到记录器 (org.jnp.interfaces.TimedSocketFactory) 的附加程序。
log4j:WARN 请正确初始化 log4j 系统。

看起来 log4j 配置文件需要位于 Maven 插件 的类路径中,但我不知道如何在其中包含随机文件,只包含依赖项。我真的很想设置此信息,以便我可以从 JBoss 库获取调试信息,以便解决我的问题。

I'm using the Cargo Maven plugin to deploy a WAR to a remote server, and I'm having problems. I'll probably create a second question for that problem, but this one is about overriding a Maven plugin's log4j configuration. Cargo uses JBoss' client libraries to ship stuff to JBoss servers (which I'm trying to do.) The JBoss library uses log4j. Cargo doesn't set up any sort of mapping layer that I know of.

So, essentially, log messages are occurring in the dependent library of a Maven plugin. I tried setting -Dlog4j.debug and got this information:

log4j: Trying to find [log4j.xml] using ClassRealm[plugin>org.codehaus.cargo:cargo-maven2-plugin:1.0.5, parent: ClassRealm[maven.api, parent: null]] class loader.
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
log4j: Trying to find [log4j.properties] using context classloader ClassRealm[plugin>org.codehaus.cargo:cargo-maven2-plugin:1.0.5, parent: ClassRealm[maven.api, parent: null]].
log4j: Using URL [jar:file:/C:/Users/username/.m2/repository/org/jboss/jbossts/jbossjts/4.13.1.Final/jbossjts-4.13.1.Final.jar!/log4j.properties] for automatic log4j configuration.
log4j: Reading configuration from URL jar:file:/C:/Users/username/.m2/repository/org/jboss/jbossts/jbossjts/4.13.1.Final/jbossjts-4.13.1.Final.jar!/log4j.properties
log4j: Could not find root logger information. Is this OK?
log4j: Parsing for [com.arjuna] with value=[INFO, default, stdout].
log4j: Level token is [INFO].
log4j: Category com.arjuna set to INFO
log4j: Parsing appender named "default".
log4j: Parsing layout options for "default".
log4j: Setting property [conversionPattern] to [%d [%t] %-5p %c - %m%n].
log4j: End of parsing for "default".
log4j: Setting property [maxBackupIndex] to [2].
log4j: Setting property [file] to [transaction.log].
log4j: Setting property [maxFileSize] to [500KB].
log4j: setFile called: transaction.log, true
log4j: setFile ended
log4j: Parsed "default" options.
log4j: Parsing appender named "stdout".
log4j: Parsing layout options for "stdout".
log4j: Setting property [conversionPattern] to [%d [%t] %-5p %c - %m%n].
log4j: End of parsing for "stdout".
log4j: Setting property [threshold] to [WARN].
log4j: Parsed "stdout" options.
log4j: Handling log4j.additivity.com.arjuna=[null]
log4j: Finished configuring.
log4j:WARN No appenders could be found for logger (org.jnp.interfaces.TimedSocketFactory).
log4j:WARN Please initialize the log4j system properly.

Then I tried setting -Dlog4j.configuration=mylog4j.properties but got this:

log4j: Trying to find [mylog4j.properties] using context classloader ClassRealm[plugin>org.codehaus.cargo:cargo-maven2-plugin:1.0.5, parent: ClassRealm[maven.api, parent: null]].
log4j: Trying to find [mylog4j.properties] using ClassRealm[plugin>org.codehaus.cargo:cargo-maven2-plugin:1.0.5, parent: ClassRealm[maven.api, parent: null]] class loader.
log4j: Trying to find [mylog4j.properties] using ClassLoader.getSystemResource().
log4j: Could not find resource: [mylog4j.properties].
log4j:WARN No appenders could be found for logger (org.jnp.interfaces.TimedSocketFactory).
log4j:WARN Please initialize the log4j system properly.

It would appear that the log4j configuration file needs to be in the Maven plugin's classpath, but I don't know how to include random files there, only dependencies. I really want to set this information so that I can get debug information from the JBoss libraries in order to troubleshoot my problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葮薆情 2024-10-15 23:00:30

使用log4j.configuration,您将设置一个资源字符串。查看 log4j 默认初始化过程 和示例。

如果您使用这样的语法,

-Dlog4j.configuration=mylog4j.properties

则该文件应该位于类路径中。但您也可以使用这样的语法

-Dlog4j.configuration=file:/<path>/mylog4j.properties

来指定完全限定的文件位置。

With log4j.configuration you will set a resource string. Have a look at the log4j default initialization process and the examples.

If you use a syntax like this

-Dlog4j.configuration=mylog4j.properties

the file is expected in the classpath. But you can also use a syntax like this

-Dlog4j.configuration=file:/<path>/mylog4j.properties

to specify a fully qualified file location.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文