Re: "ERROR StatusLogger Reconfiguration failed" when running log4j-1.2-api from uber-jar

2022-07-07 Thread Ralph Goers
The recommended approach is to do what Spring Boot does - build 
a jar that has all its dependent jars in a directory. A jar is just a zip file 
so you can either unzip it before running or have the start up program 
set the classpath to the directory inside the zip. Of course, that may 
mean you need a custom ClassLoader but I’d be willing to bet you can 
find something that already does this. Or build it as a Spring Boot app.

Ralph

> On Jul 7, 2022, at 4:06 AM, Alain Désilets  wrote:
> 
> On Thu, Jul 7, 2022 at 6:14 AM Piotr P. Karwasz 
> wrote:
> 
>> 
>> 
>> The removal of the `Log4j2Plugins.dat` files is exactly the source of
>> the problem. Log4j2 uses these files to load the list of available
>> plugins (like the Log4j 1.2 configuration factories), if it does not
>> find them it falls back to scanning the
>> `org.apache.logging.log4j.core` package. The plugins from
>> `log4j-1.2-api` are not in this package. Instead of deleting these
>> files you should merge them using the Maven shade plugin proposed by
>> Ralph.
>> 
> 
> Thx Piotr,
> 
> This is interesting. The reason why I added this filter is that I was
> getting a
> 
> log4j2 ERROR StatusLogger Unrecognized conversion specifier
> 
> Reading about this, I found several posts that said the solution was to
> filter the Log4j2Plugins.dat files.
> 
> So I should merge the files instead?
> 
> Question: Would I get the same issue if instead of creating an Uber jar, I
> created a jar with just my project's classes, and then ran it with
> 
> -cp log4j2-compatibility-1.0.0.jar:/path/to/the/depencies/*.jar


-
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org



Re: "ERROR StatusLogger Reconfiguration failed" when running log4j-1.2-api from uber-jar

2022-07-07 Thread Alain Désilets
On Thu, Jul 7, 2022 at 6:14 AM Piotr P. Karwasz 
wrote:

>
>
> The removal of the `Log4j2Plugins.dat` files is exactly the source of
> the problem. Log4j2 uses these files to load the list of available
> plugins (like the Log4j 1.2 configuration factories), if it does not
> find them it falls back to scanning the
> `org.apache.logging.log4j.core` package. The plugins from
> `log4j-1.2-api` are not in this package. Instead of deleting these
> files you should merge them using the Maven shade plugin proposed by
> Ralph.
>

Thx Piotr,

This is interesting. The reason why I added this filter is that I was
getting a

log4j2 ERROR StatusLogger Unrecognized conversion specifier

Reading about this, I found several posts that said the solution was to
filter the Log4j2Plugins.dat files.

So I should merge the files instead?

Question: Would I get the same issue if instead of creating an Uber jar, I
created a jar with just my project's classes, and then ran it with

-cp log4j2-compatibility-1.0.0.jar:/path/to/the/depencies/*.jar


Re: "ERROR StatusLogger Reconfiguration failed" when running log4j-1.2-api from uber-jar

2022-07-07 Thread Piotr P. Karwasz
Hi Alain,

On Thu, 7 Jul 2022 at 11:35, Alain Désilets  wrote:
> If you look at my pom, you can see that there is a filter in the
> configuration of the shade plugin that remove the Log4j2Plugins.dat files.
> This seems to work because
>
> jar -tf iutools-core-1.0.2-jar-with-dependencies.jar | grep Log4j2Plugins
>
>
> produces an empty list.
>
> So I think the problem lies elsewhere.

The removal of the `Log4j2Plugins.dat` files is exactly the source of
the problem. Log4j2 uses these files to load the list of available
plugins (like the Log4j 1.2 configuration factories), if it does not
find them it falls back to scanning the
`org.apache.logging.log4j.core` package. The plugins from
`log4j-1.2-api` are not in this package. Instead of deleting these
files you should merge them using the Maven shade plugin proposed by
Ralph.

As an alternative you can replace the `maven-shade-plugin` with the
`spring-boot-maven-plugin` that creates single JAR file applications
without squashing all jars into one:
https://docs.spring.io/spring-boot/docs/current/maven-plugin/reference/htmlsingle/#goals-repackage

Piotr

-
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org



Re: "ERROR StatusLogger Reconfiguration failed" when running log4j-1.2-api from uber-jar

2022-07-07 Thread Alain Désilets
Le jeu. 7 juill. 2022, 2 h 54 a.m., Ralph Goers 
a écrit :

> When you run as an uber jar you are most likely breaking things.
>
> Log4j uses a file named Log4j2Plugins.dat to define its plugins. Every jar
> that has Log4j plugins will have one. When you create an uber jar most
> likely only one is left and it probably doesn’t contain the core Log4j
> stuff.
>
> To solve this you need to use
> https://github.com/edwgiz/maven-shaded-log4j-transformer.
>
> Ralph
>

Thx for the reply Ralph.

If you look at my pom, you can see that there is a filter in the
configuration of the shade plugin that remove the Log4j2Plugins.dat files.
This seems to work because

jar -tf iutools-core-1.0.2-jar-with-dependencies.jar | grep Log4j2Plugins


produces an empty list.

So I think the problem lies elsewhere.

Alain


Re: "ERROR StatusLogger Reconfiguration failed" when running log4j-1.2-api from uber-jar

2022-07-07 Thread Ralph Goers
When you run as an uber jar you are most likely breaking things. 

Log4j uses a file named Log4j2Plugins.dat to define its plugins. Every jar that 
has Log4j plugins will have one. When you create an uber jar most likely only 
one is left and it probably doesn’t contain the core Log4j stuff.

To solve this you need to use 
https://github.com/edwgiz/maven-shaded-log4j-transformer.

Ralph

> On Jul 6, 2022, at 5:07 AM, Alain Désilets  wrote:
> 
> Here is another interesting thing.
> 
> If I remove the log4j-1.2-api dependency from the pom, then the when I try
> to build the project from Terminal, I get the following failure:
> 
> [*ERROR*] 
> */Users/desilets/Documents/GitRepositories/SpikeLog4j2Compatibility/src/main/java/org/examples/HelloWorld.java:[3,24]
> package org.apache.log4j does not exist*
> 
> 
> Which is what I would expect.
> 
> But the project builds and runs without problem in intelliJ. This is true
> even if I do "Invalidate caches and Restart".
> 
> Very strange.
> 
> On Wed, Jul 6, 2022 at 7:27 AM Alain Désilets 
> wrote:
> 
>> I am trying to use log4j2 through log4j-1.2-api in the context of an
>> uber-jar created with the maven shade plugin and am experiencing issues.
>> 
>> I wrote a simple HelloWorld class that illustrates the issue.
>> 
>> When I run this class through intelliJ, everything works fine. But when I
>> run it through a terminal, I get
>> 
>> ERROR StatusLogger Reconfiguration failed: No configuration found for
>> '55f96302' at 'null' in 'null'
>> 
>> 
>> In both cases, I invoke the command with
>> 
>> -Dlog4j.configuration=/path/to/my/log4j.properties
>> 
>> 
>> And the log4j.properties is in the old log4j style (i.e. NOT log4j2 style).
>> 
>> Not sure what I am doing wrong.
>> 
>> One thing I notice is that the class path is different in both situations.
>> When running through intelliJ, it contains a great number of jars,
>> including:
>> 
>> 
>>   -
>>   
>> .m2/repository/org/apache/logging/log4j/log4j-core/2.17.2/log4j-core-2.17.2.jar
>>   -
>>   
>> .m2/repository/org/apache/logging/log4j/log4j-api/2.17.2/log4j-api-2.17.2.jar
>>   -
>>   
>> .m2/repository/org/apache/logging/log4j/log4j-1.2-api/2.17.2/log4j-1.2-api-2.17.2.jar
>> 
>> whereas when I run it from terminal, it just contains my one uber-jar. But
>> based on the content of my pom, I expect that the uber jar will contain
>> classes from those same log4j jars.
>> 
>> Here are the details of this HelloWorld example.
>> 
>> 
>> This is the HelloWorld class
>> 
>> package org.examples;
>> 
>> import org.apache.log4j.Logger;
>> 
>> import java.net.URL;
>> import java.net.URLClassLoader;
>> 
>> public class HelloWorld {
>> 
>>  public static void main(String[] args) {
>>printClassPath();
>>Logger logger = Logger.getLogger("org.examples.HelloWorld");
>>logger.trace("Hello from Logger");
>>  }
>> 
>>  private static void printClassPath() {
>>ClassLoader cl = ClassLoader.getSystemClassLoader();
>>URL[] urls = ((URLClassLoader)cl).getURLs();
>> 
>>System.out.println("Class path is:");
>>for(URL url: urls){
>>  System.out.println(url.getFile());
>>}
>>  }
>> }
>> 
>> 
>> And here is the pom:
>> 
>> http://maven.apache.org/POM/4.0.0; 
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; 
>> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
>> http://maven.apache.org/xsd/maven-4.0.0.xsd;>
>> 
>>  4.0.0
>>  org.examples
>>  log4j2-compatibility
>>  1.0.0
>> 
>>  
>>2.17.2
>>  
>> 
>>  
>>
>>  
>>  
>>org.apache.maven.plugins
>>maven-shade-plugin
>>3.1.0
>>
>>  true
>>  jar-with-dependencies
>>  
>>
>>  *:*
>>  
>>
>>**/Log4j2Plugins.dat
>>  
>>
>>  
>>
>>
>>  
>>package
>>
>>  shade
>>
>>  
>>
>>  
>>
>>  
>> 
>>  
>> 
>>
>>  org.apache.logging.log4j
>>  log4j-core
>>  ${log4j.version}
>>
>> 
>>
>>  org.apache.logging.log4j
>>  log4j-1.2-api
>>  ${log4j.version}
>>
>> 
>>  
>> 
>> 
>> 
>> And here is the log4.properties file
>> 
>> # Log to stdout only
>> log4j.rootLogger=warn, stdout
>> 
>> # Configure the stdout logger
>> log4j.appender.stdout=org.apache.log4j.ConsoleAppender
>> log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
>> log4j.appender.stdout.layout.ConversionPattern =-- %c{2}: %m%n
>> 
>> # Activate some traces
>> log4j.logger.org.examples.HelloWorld=trace
>> 
>> 


-
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org



Re: "ERROR StatusLogger Reconfiguration failed" when running log4j-1.2-api from uber-jar

2022-07-06 Thread Alain Désilets
Here is another interesting thing.

If I remove the log4j-1.2-api dependency from the pom, then the when I try
to build the project from Terminal, I get the following failure:

[*ERROR*] 
*/Users/desilets/Documents/GitRepositories/SpikeLog4j2Compatibility/src/main/java/org/examples/HelloWorld.java:[3,24]
package org.apache.log4j does not exist*


Which is what I would expect.

But the project builds and runs without problem in intelliJ. This is true
even if I do "Invalidate caches and Restart".

Very strange.

On Wed, Jul 6, 2022 at 7:27 AM Alain Désilets 
wrote:

> I am trying to use log4j2 through log4j-1.2-api in the context of an
> uber-jar created with the maven shade plugin and am experiencing issues.
>
> I wrote a simple HelloWorld class that illustrates the issue.
>
> When I run this class through intelliJ, everything works fine. But when I
> run it through a terminal, I get
>
> ERROR StatusLogger Reconfiguration failed: No configuration found for
> '55f96302' at 'null' in 'null'
>
>
> In both cases, I invoke the command with
>
> -Dlog4j.configuration=/path/to/my/log4j.properties
>
>
> And the log4j.properties is in the old log4j style (i.e. NOT log4j2 style).
>
> Not sure what I am doing wrong.
>
> One thing I notice is that the class path is different in both situations.
> When running through intelliJ, it contains a great number of jars,
> including:
>
>
>-
>
> .m2/repository/org/apache/logging/log4j/log4j-core/2.17.2/log4j-core-2.17.2.jar
>-
>
> .m2/repository/org/apache/logging/log4j/log4j-api/2.17.2/log4j-api-2.17.2.jar
>-
>
> .m2/repository/org/apache/logging/log4j/log4j-1.2-api/2.17.2/log4j-1.2-api-2.17.2.jar
>
> whereas when I run it from terminal, it just contains my one uber-jar. But
> based on the content of my pom, I expect that the uber jar will contain
> classes from those same log4j jars.
>
> Here are the details of this HelloWorld example.
>
>
> This is the HelloWorld class
>
> package org.examples;
>
> import org.apache.log4j.Logger;
>
> import java.net.URL;
> import java.net.URLClassLoader;
>
> public class HelloWorld {
>
>   public static void main(String[] args) {
> printClassPath();
> Logger logger = Logger.getLogger("org.examples.HelloWorld");
> logger.trace("Hello from Logger");
>   }
>
>   private static void printClassPath() {
> ClassLoader cl = ClassLoader.getSystemClassLoader();
> URL[] urls = ((URLClassLoader)cl).getURLs();
>
> System.out.println("Class path is:");
> for(URL url: urls){
>   System.out.println(url.getFile());
> }
>   }
> }
>
>
> And here is the pom:
>
> http://maven.apache.org/POM/4.0.0; 
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; 
> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
> http://maven.apache.org/xsd/maven-4.0.0.xsd;>
>
>   4.0.0
>   org.examples
>   log4j2-compatibility
>   1.0.0
>
>   
> 2.17.2
>   
>
>   
> 
>   
>   
> org.apache.maven.plugins
> maven-shade-plugin
> 3.1.0
> 
>   true
>   jar-with-dependencies
>   
> 
>   *:*
>   
> 
> **/Log4j2Plugins.dat
>   
> 
>   
> 
> 
>   
> package
> 
>   shade
> 
>   
> 
>   
> 
>   
>
>   
>
> 
>   org.apache.logging.log4j
>   log4j-core
>   ${log4j.version}
> 
>
> 
>   org.apache.logging.log4j
>   log4j-1.2-api
>   ${log4j.version}
> 
>
>   
> 
>
>
> And here is the log4.properties file
>
> # Log to stdout only
> log4j.rootLogger=warn, stdout
>
> # Configure the stdout logger
> log4j.appender.stdout=org.apache.log4j.ConsoleAppender
> log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
> log4j.appender.stdout.layout.ConversionPattern =-- %c{2}: %m%n
>
> # Activate some traces
> log4j.logger.org.examples.HelloWorld=trace
>
>


"ERROR StatusLogger Reconfiguration failed" when running log4j-1.2-api from uber-jar

2022-07-06 Thread Alain Désilets
I am trying to use log4j2 through log4j-1.2-api in the context of an
uber-jar created with the maven shade plugin and am experiencing issues.

I wrote a simple HelloWorld class that illustrates the issue.

When I run this class through intelliJ, everything works fine. But when I
run it through a terminal, I get

ERROR StatusLogger Reconfiguration failed: No configuration found for
'55f96302' at 'null' in 'null'


In both cases, I invoke the command with

-Dlog4j.configuration=/path/to/my/log4j.properties


And the log4j.properties is in the old log4j style (i.e. NOT log4j2 style).

Not sure what I am doing wrong.

One thing I notice is that the class path is different in both situations.
When running through intelliJ, it contains a great number of jars,
including:


   -
   
.m2/repository/org/apache/logging/log4j/log4j-core/2.17.2/log4j-core-2.17.2.jar
   -
   .m2/repository/org/apache/logging/log4j/log4j-api/2.17.2/log4j-api-2.17.2.jar
   -
   
.m2/repository/org/apache/logging/log4j/log4j-1.2-api/2.17.2/log4j-1.2-api-2.17.2.jar

whereas when I run it from terminal, it just contains my one uber-jar. But
based on the content of my pom, I expect that the uber jar will contain
classes from those same log4j jars.

Here are the details of this HelloWorld example.


This is the HelloWorld class

package org.examples;

import org.apache.log4j.Logger;

import java.net.URL;
import java.net.URLClassLoader;

public class HelloWorld {

  public static void main(String[] args) {
printClassPath();
Logger logger = Logger.getLogger("org.examples.HelloWorld");
logger.trace("Hello from Logger");
  }

  private static void printClassPath() {
ClassLoader cl = ClassLoader.getSystemClassLoader();
URL[] urls = ((URLClassLoader)cl).getURLs();

System.out.println("Class path is:");
for(URL url: urls){
  System.out.println(url.getFile());
}
  }
}


And here is the pom:

http://maven.apache.org/POM/4.0.0;
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd;>

  4.0.0
  org.examples
  log4j2-compatibility
  1.0.0

  
2.17.2
  

  

  
  
org.apache.maven.plugins
maven-shade-plugin
3.1.0

  true
  jar-with-dependencies
  

  *:*
  

**/Log4j2Plugins.dat
  

  


  
package

  shade

  

  

  

  


  org.apache.logging.log4j
  log4j-core
  ${log4j.version}



  org.apache.logging.log4j
  log4j-1.2-api
  ${log4j.version}


  



And here is the log4.properties file

# Log to stdout only
log4j.rootLogger=warn, stdout

# Configure the stdout logger
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern =-- %c{2}: %m%n

# Activate some traces
log4j.logger.org.examples.HelloWorld=trace