问题描述
我正在使用Cargo Maven插件将战争部署到远程服务器,并且遇到了问题.我可能会为该问题创建第二个问题,但是这个问题是关于覆盖Maven插件的Log4J配置.货物使用JBOSS的客户库将东西运送到JBOSS服务器(我要做的.)JBOSS库使用Log4J.货物没有设置我知道的任何映射层.
因此,从本质上讲,日志消息发生在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 插件的classpath中,但我不知道如何在其中包含随机文件,只有依赖项.我真的想设置此信息,以便可以从JBOSS库中获取调试信息,以解决我的问题.
推荐答案
使用log4j.configuration您将设置一个资源字符串.看看log4j 默认初始化过程 P>
如果您使用这样的语法
-Dlog4j.configuration=mylog4j.properties
class路径中的文件预期.但是您也可以使用这样的语法
-Dlog4j.configuration=file:/<path>/mylog4j.properties
指定一个完全合格的文件位置.
问题描述
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.
推荐答案
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.