[ 
https://issues.apache.org/jira/browse/LOG4J2-1659?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Gary Gregory updated LOG4J2-1659:
---------------------------------
    Attachment: logging-log4j2.patch

I have attached my proposal. The build passes locally for me.

Here is the explanation. The plugin processor is configured with a new option 
from the parent POM like so:

{code:xml}
<compilerArguments>
  
<ApluginCacheFile>META-INF/org/apache/logging/log4j/core/config/plugins/${project.groupId}-${project.artifactId}.dat</ApluginCacheFile>
</compilerArguments>
{code}

All DAT files end up in the same folder for all jars BUT with different files 
names. If you shade Log4j jars into an uber jar you end up with one DAT file 
per jar, without name clashes.

When the DAT files are collected by the plugin registry, the call to 
{{loader.getResources()}} is made with the FOLDER name 
({{"META-INF/org/apache/logging/log4j/core/config/plugins"}}), not the FILE 
name. This allows us to loop over all folders from all jars and classpath 
entries. From there I call {{openStream()}} on each collected URL folders which 
lists the contents of the folder which I filter for DAT files only and build 
new URL objects for DAT files. Then it's the same as usual, load each DAT file 
URL.

DAT files for TESTs remain with the old file name in the target/test-classes 
folder.

The patch still looks for the old DAT file names for compatibility.


> Facilitate shading Log4j into an application's uber jar
> -------------------------------------------------------
>
>                 Key: LOG4J2-1659
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1659
>             Project: Log4j 2
>          Issue Type: Improvement
>            Reporter: Gary Gregory
>         Attachments: logging-log4j2.patch
>
>
> Facilitate shading Log4j into an application's uber jar.
> I have a use case where I create an Uber jar for a proprietary JDBC driver 
> and all of its dependencies, which includes Log4j (now) 2.7.
> The result is a big fat jar that gets deployed in JBoss Wildfly 9.
> When the server starts up, logging is all messed up:
> {noformat}
> 00:32:06,955 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-5)  
> WFLYSRV0059: Class Path entry log4j-api-2.7.jar in 
> /content/dv-jdbc-3.1.201610281922-all.jar  does not point to a valid jar for 
> a Class-Path reference.
> 00:32:06,960 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-5)  
> WFLYSRV0059: Class Path entry log4j-core-2.7.jar in 
> /content/dv-jdbc-3.1.201610281922-all.jar  does not point to a valid jar for 
> a Class-Path reference.
> 00:32:06,961 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-5)  
> WFLYSRV0059: Class Path entry log4j-iostreams-2.7.jar in 
> /content/dv-jdbc-3.1.201610281922-all.jar  does not point to a valid jar for 
> a Class-Path reference.
> 00:32:06,961 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-5)  
> WFLYSRV0059: Class Path entry icu4j-57.1.jar in 
> /content/dv-jdbc-3.1.201610281922-all.jar  does not point to a valid jar for 
> a Class-Path reference.
> 00:32:06,962 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-5)  
> WFLYSRV0059: Class Path entry icu4j-charset-57.1.jar in 
> /content/dv-jdbc-3.1.201610281922-all.jar  does not point to a valid jar for 
> a Class-Path reference.
> 00:32:06,962 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-5)  
> WFLYSRV0059: Class Path entry log4j-jcl-2.7.jar in 
> /content/dv-jdbc-3.1.201610281922-all.jar  does not point to a valid jar for 
> a Class-Path reference.
> 00:32:06,963 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-5)  
> WFLYSRV0059: Class Path entry commons-logging-1.2.jar in 
> /content/dv-jdbc-3.1.201610281922-all.jar  does not point to a valid jar for 
> a Class-Path reference.
> 00:32:06,963 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-5)  
> WFLYSRV0059: Class Path entry log4j-jmx-gui-2.7.jar in 
> /content/dv-jdbc-3.1.201610281922-all.jar  does not point to a valid jar for 
> a Class-Path reference.
> 00:32:06,963 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-5)  
> WFLYSRV0059: Class Path entry log4j-nosql-2.7.jar in 
> /content/dv-jdbc-3.1.201610281922-all.jar  does not point to a valid jar for 
> a Class-Path reference.
> 00:32:06,964 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-5)  
> WFLYSRV0059: Class Path entry log4j-taglib-2.7.jar in 
> /content/dv-jdbc-3.1.201610281922-all.jar  does not point to a valid jar for 
> a Class-Path reference.
> 00:32:06,964 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-5)  
> WFLYSRV0059: Class Path entry log4j-web-2.7.jar in 
> /content/dv-jdbc-3.1.201610281922-all.jar  does not point to a valid jar for 
> a Class-Path reference.
> 00:32:06,964 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-5)  
> WFLYSRV0059: Class Path entry commons-dbcp2-2.1.1.jar in 
> /content/dv-jdbc-3.1.201610281922-all.jar  does not point to a valid jar for 
> a Class-Path reference.
> 00:32:06,965 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-5)  
> WFLYSRV0059: Class Path entry commons-pool2-2.4.2.jar in 
> /content/dv-jdbc-3.1.201610281922-all.jar  does not point to a valid jar for 
> a Class-Path reference.
> 00:32:06,965 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-5)  
> WFLYSRV0059: Class Path entry jansi-1.13.jar in 
> /content/dv-jdbc-3.1.201610281922-all.jar  does not point to a valid jar for 
> a Class-Path reference.
> 00:32:06,965 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-5)  
> WFLYSRV0059: Class Path entry jcommander-1.48.jar in 
> /content/dv-jdbc-3.1.201610281922-all.jar  does not point to a valid jar for 
> a Class-Path reference.
> 00:32:06,966 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-5)  
> WFLYSRV0059: Class Path entry log4j-1.2-api-2.7.jar in 
> /content/dv-jdbc-3.1.201610281922-all.jar  does not point to a valid jar for 
> a Class-Path reference.
> 00:32:07,435 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized format specifier [d]
> 00:32:07,442 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized conversion specifier [d] starting at position 16 in conversion 
> pattern.
> 00:32:07,476 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized format specifier [thread]
> 00:32:07,479 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized conversion specifier [thread] starting at position 25 in 
> conversion pattern.
> 00:32:07,492 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized format specifier [level]
> 00:32:07,538 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized conversion specifier [level] starting at position 35 in 
> conversion pattern.
> 00:32:07,556 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized format specifier [logger]
> 00:32:07,558 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized conversion specifier [logger] starting at position 47 in 
> conversion pattern.
> 00:32:07,558 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized format specifier [msg]
> 00:32:07,559 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized conversion specifier [msg] starting at position 54 in conversion 
> pattern.
> 00:32:07,560 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized format specifier [n]
> 00:32:07,561 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized conversion specifier [n] starting at position 56 in conversion 
> pattern.
> 00:32:07,593 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger No 
> log4j2 configuration file found. Using default configuration: logging only 
> errors to the console.
> 00:32:07,595 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized format specifier [d]
> 00:32:07,595 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized conversion specifier [d] starting at position 16 in conversion 
> pattern.
> 00:32:07,596 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized format specifier [thread]
> 00:32:07,597 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized conversion specifier [thread] starting at position 25 in 
> conversion pattern.
> 00:32:07,597 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized format specifier [level]
> 00:32:07,598 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized conversion specifier [level] starting at position 35 in 
> conversion pattern.
> 00:32:07,598 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized format specifier [logger]
> 00:32:07,599 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized conversion specifier [logger] starting at position 47 in 
> conversion pattern.
> 00:32:07,600 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized format specifier [msg]
> 00:32:07,600 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized conversion specifier [msg] starting at position 54 in conversion 
> pattern.
> 00:32:07,601 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized format specifier [n]
> 00:32:07,602 ERROR [stderr] (MSC service thread 1-2)  ERROR StatusLogger 
> Unrecognized conversion specifier [n] starting at position 56 in conversion 
> pattern.
> {noformat}
> What to do? It looks like the uber jar picks up the last plugin DAT file 
> (log4j-web).
> Unfortunately, https://github.com/edwgiz/maven-shaded-log4j-transformer does 
> not work or I could not get it to work I should say.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to