How do I override a Maven Plugin's log4j Configuration?

对着背影说爱祢 提交于 2019-12-06 01:37:29

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/4520995/how-do-i-override-a-maven-plugins-log4j-configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!