6

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

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

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.

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

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.

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

4

1 回答 1

10

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

如果你使用这样的语法

-Dlog4j.configuration=mylog4j.properties

该文件应在类路径中。但是你也可以使用这样的语法

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

指定一个完全限定的文件位置。

于 2011-08-23T19:19:00.560 回答