javamavenlog4jlog4j2

Startup log4j2 ERROR Unrecognized conversion specifier and format specifier


In a project using maven, I have the same issue as described in log4j2 ERROR StatusLogger Unrecognized conversion specifier. But the problem persist even after implementing both solutions described in the answer to that question. i.e. exclude Log4jPlugins.dat and use the manifest transformer plugin for log4j.

Moreover I can confirm that the Jar file does not contain a file name Log4j2Plugins.dat nor under META-INF nor anywhere else in the jar tree structure.

Error message:

2024-06-22T00:41:49.937Z main ERROR Unrecognized format specifier [d]                                                     
2024-06-22T00:41:49.952Z main ERROR Unrecognized conversion specifier [d] starting at position 16 in conversion pattern.
2024-06-22T00:41:49.953Z main ERROR Unrecognized format specifier [thread]                                              
2024-06-22T00:41:49.953Z main ERROR Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern.
2024-06-22T00:41:49.954Z main ERROR Unrecognized format specifier [level]                                              
2024-06-22T00:41:49.954Z main ERROR Unrecognized conversion specifier [level] starting at position 35 in conversion pattern.
2024-06-22T00:41:49.954Z main ERROR Unrecognized format specifier [logger]                                              
2024-06-22T00:41:49.954Z main ERROR Unrecognized conversion specifier [logger] starting at position 47 in conversion pattern.
2024-06-22T00:41:49.955Z main ERROR Unrecognized format specifier [msg]                                                 
2024-06-22T00:41:49.955Z main ERROR Unrecognized conversion specifier [msg] starting at position 54 in conversion pattern.
2024-06-22T00:41:49.955Z main ERROR Unrecognized format specifier [n]                                                   
2024-06-22T00:41:49.956Z main ERROR Unrecognized conversion specifier [n] starting at position 56 in conversion pattern.
2024-06-22T00:41:49.964Z main ERROR Unrecognized format specifier [d]                                                   
2024-06-22T00:41:49.964Z main ERROR Unrecognized conversion specifier [d] starting at position 16 in conversion pattern.
2024-06-22T00:41:49.964Z main ERROR Unrecognized format specifier [thread]    
2024-06-22T00:41:49.965Z main ERROR Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern.
2024-06-22T00:41:49.965Z main ERROR Unrecognized format specifier [level]                 
2024-06-22T00:41:49.965Z main ERROR Unrecognized conversion specifier [level] starting at position 35 in conversion pattern.
2024-06-22T00:41:49.965Z main ERROR Unrecognized format specifier [logger]
2024-06-22T00:41:49.965Z main ERROR Unrecognized conversion specifier [logger] starting at position 47 in conversion pattern.
2024-06-22T00:41:49.965Z main ERROR Unrecognized format specifier [msg]                                
2024-06-22T00:41:49.965Z main ERROR Unrecognized conversion specifier [msg] starting at position 54 in conversion pattern.
2024-06-22T00:41:49.965Z main ERROR Unrecognized format specifier [n]             
2024-06-22T00:41:49.966Z main ERROR Unrecognized conversion specifier [n] starting at position 56 in conversion pattern.
2024-06-22T00:41:51.876Z main ERROR Unrecognized format specifier [p]
2024-06-22T00:41:51.876Z main ERROR Unrecognized conversion specifier [p] starting at position 4 in conversion pattern.
2024-06-22T00:41:51.877Z main ERROR Unrecognized format specifier [d]
2024-06-22T00:41:51.877Z main ERROR Unrecognized conversion specifier [d] starting at position 21 in conversion pattern.
2024-06-22T00:41:51.877Z main ERROR Unrecognized format specifier [C]                                 
2024-06-22T00:41:51.877Z main ERROR Unrecognized conversion specifier [C] starting at position 27 in conversion pattern.                        
2024-06-22T00:41:51.877Z main ERROR Unrecognized format specifier [m]
2024-06-22T00:41:51.877Z main ERROR Unrecognized conversion specifier [m] starting at position 32 in conversion pattern.
2024-06-22T00:41:51.877Z main ERROR Unrecognized format specifier [n]
2024-06-22T00:41:51.877Z main ERROR Unrecognized conversion specifier [n] starting at position 35 in conversion pattern.

Extract from relevant maven pom:

plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <dependencies>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-transform-maven-shade-plugin-extensions</artifactId>
      <version>0.1.0</version>
    </dependency>
  </dependencies>
  <executions>
    <execution>
      <id>package-jar</id>
      <goals>
        <goal>shade</goal>
      </goals>
      <phase>package</phase>
      <configuration>
        <minimizeJar>true</minimizeJar>
        <createDependencyReducedPom>false</createDependencyReducedPom>
        <artifactSet>
          <excludes>
            <exclude>org.broadinstitute.gatk:gsalib:tar.gz:*</exclude>
            <exclude>org.broadinstitute.gatk:*:tar.bz2:example-resources</exclude>
          </excludes>
        </artifactSet>
        <filters>
          <filter>
            <artifact>*:*</artifact>
            <excludes>
              <exclude>META-INF/services/javax.annotation.processing.Processor</exclude>
              <exclude>**/Log4j2Plugins.dat</exclude>
            </excludes>
          </filter>
        </filters>
        <transformers>
          <transformer implementation="org.apache.logging.log4j.maven.plugins.shade.transformer.Log4j2PluginCacheFileTransformer"/>
          <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
            <manifestEntries>
              <Multi-Release>true</Multi-Release>
              <Main-Class>${app.main.class}</Main-Class>
            </manifestEntries>
          </transformer>
          <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
            <resource>${resource.bundle.path}</resource>
          </transformer>
        </transformers>
      </configuration>
    </execution>
  </executions>
</plugin>

Solution

  • In the end I found the culprit in my case so I'm posting in case it helps someone else issue; since these messages seem to be most of the time due to the multiple Log4j2Plugins.dat conflict with or without maven involved, is difficult to address possible alternative issues that cause the seem error messages.

    In my case the problem was that our build had some optional jar minimization feature on from the maven-shade-plugin:

    
    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-shade-plugin</artifactId>
       <version>3.4.1</version>
       <executions>
          <execution>
          <id>package-jar</id>
          <goals>
            <goal>shade</goal>
          </goals>
          <phase>none</phase>
          <configuration>
            <minimizeJar>true</minimizeJar>
            <!-- ... -->
          </configuration>
        </exectuion>
      </executions>
    </plugin>  
       
    

    Change the true above for a false was everything that was needed.

    That resulted in many classes that are not explicitly referenced in the code to be dropped out from the jar including classes under org.apache.logging.log4j.core.pattern.**. So the core supporting plugging/pattern were not loaded resulting in the init ERROR messages.

    log4j-core's logger (StatusLogger) would output INFO messages when such plugins were referenced within Log4j2Plugins.dat which by default is not output in my case thus silencing the cause of the issue. I guess I could have avoided expending as much time as I did figuring it out if I had change the StatusLogger output level but perhaps a WARNING rather than INFO makes more sense (jar minimizers should then have the option to explicitly opt out).