我正在使用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 plugin 的类路径中,但我不知道如何在那里包含随机文件,只有依赖项。我真的想设置这些信息,以便从JBoss库中获取调试信息,以解决我的问题。
答案 0 :(得分:8)
使用log4j.configuration
,您将设置资源字符串。看一下log4j default initialization process和示例。
如果您使用这样的语法
-Dlog4j.configuration=mylog4j.properties
该文件在类路径中是预期的。但您也可以使用这样的语法
-Dlog4j.configuration=file:/<path>/mylog4j.properties
指定完全限定的文件位置。