Quantcast
Channel: User BSP0 - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Log4j appender plugin "ERROR StatusLogger Unrecognized format specifier" when run from an executable jar

$
0
0

I am using IntelliJ IDEA and Maven. I am making a server application in JavaFX and wanted to use Log4j to display logs in the server console. When compiling the program in the IDE, everything works as expected, however when exporting it as an executable jar using an artifact build option, I get errors on startup:

ERROR StatusLogger Unrecognized format specifier [d]ERROR StatusLogger Unrecognized conversion specifier [d] starting at position 16 in conversion pattern.ERROR StatusLogger Unrecognized format specifier [thread]ERROR StatusLogger Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern.ERROR StatusLogger Unrecognized format specifier [level]ERROR StatusLogger Unrecognized conversion specifier [level] starting at position 35 in conversion pattern.ERROR StatusLogger Unrecognized format specifier [logger]ERROR StatusLogger Unrecognized conversion specifier [logger] starting at position 47 in conversion pattern.ERROR StatusLogger Unrecognized format specifier [msg]ERROR StatusLogger Unrecognized conversion specifier [msg] starting at position 54 in conversion pattern.ERROR StatusLogger Unrecognized format specifier [n]ERROR StatusLogger Unrecognized conversion specifier [n] starting at position 56 in conversion pattern.ERROR StatusLogger Unrecognized format specifier [d]ERROR StatusLogger Unrecognized conversion specifier [d] starting at position 16 in conversion pattern.ERROR StatusLogger Unrecognized format specifier [thread]ERROR StatusLogger Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern.ERROR StatusLogger Unrecognized format specifier [level]ERROR StatusLogger Unrecognized conversion specifier [level] starting at position 35 in conversion pattern.ERROR StatusLogger Unrecognized format specifier [logger]ERROR StatusLogger Unrecognized conversion specifier [logger] starting at position 47 in conversion pattern.ERROR StatusLogger Unrecognized format specifier [msg]ERROR StatusLogger Unrecognized conversion specifier [msg] starting at position 54 in conversion pattern.ERROR StatusLogger Unrecognized format specifier [n]ERROR StatusLogger Unrecognized conversion specifier [n] starting at position 56 in conversion pattern.

The log file is not created and it looks like Log4j stops working entirely. Even removing the appender from log4j2.xml still causes the problem. Only complete removal of the plugin class allows the program to run correctly.

This is my log4j2.xml file:

<Configuration xmlns:xi="http://www.w3.org/2001/XInclude" packages="com.project.javapong" status="info"><Properties><Property name="full">[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5level] [%t] %c{1} > %msg%n</Property><Property name="compact">[%d{HH:mm:ss.SSS}] [%-5level] [%t] %c{1} > %msg%n</Property></Properties><Appenders><Console name="Console" target="SYSTEM_OUT"><PatternLayout pattern="${compact}"/></Console><RollingFile name="File" fileName="latest.log" filePattern="log-%d{yyyy-MM-dd}.log"><PatternLayout pattern="${full}"/><Policies><OnStartupTriggeringPolicy/></Policies></RollingFile><ServerLog name="ServerLog"><PatternLayout pattern="${compact}"/></ServerLog></Appenders><Loggers><Root level="info"><AppenderRef ref="Console" /><AppenderRef ref="File" /><AppenderRef ref="ServerLog" /></Root></Loggers></Configuration>

log4j plugin class:

package com.project.javapong;import javafx.application.Platform;import javafx.scene.text.Text;import org.apache.logging.log4j.Level;import org.apache.logging.log4j.core.Filter;import org.apache.logging.log4j.core.Layout;import org.apache.logging.log4j.core.LogEvent;import org.apache.logging.log4j.core.appender.AbstractAppender;import org.apache.logging.log4j.core.config.plugins.Plugin;import org.apache.logging.log4j.core.config.plugins.PluginAttribute;import org.apache.logging.log4j.core.config.plugins.PluginElement;import org.apache.logging.log4j.core.config.plugins.PluginFactory;import org.apache.logging.log4j.core.layout.PatternLayout;import java.io.Serializable;import static org.apache.logging.log4j.core.config.DefaultConfiguration.DEFAULT_PATTERN;@Plugin(name = "ServerLog", category = "Core", elementType = "appender")public class ServerLog extends AbstractAppender {    private ServerLog(String name, Filter filter, Layout<? extends Serializable> layout) {        super(name, filter, layout, false);    }    @PluginFactory    public static ServerLog createAppender(            @PluginAttribute("name") String name,            @PluginElement("Filter") Filter filter,            @PluginElement("PatternLayout") PatternLayout patternLayout) {        Layout<? extends Serializable> layout = patternLayout != null ? patternLayout : PatternLayout.newBuilder().withPattern(DEFAULT_PATTERN).build();        return new ServerLog(name, filter, layout);    }    @Override    public void append(LogEvent event) {        if (GameApp.getServerUI() != null) {            Text text = new Text();            text.setStyle("-fx-fill: #FFFFFF;");            if (event.getLevel() == Level.WARN)                text.setStyle("-fx-fill: #f2dc13;");            else if (event.getLevel() == Level.ERROR)                text.setStyle("-fx-fill: #ad1f15;");            else if (event.getLevel() == Level.DEBUG)                text.setStyle("-fx-fill: #66f2cf;");            else if (event.getLevel() == Level.FATAL)                text.setStyle("-fx-fill: #661812;");            text.setText(new String(getLayout().toByteArray(event)) + System.lineSeparator());            Platform.runLater(() ->  {                GameApp.getServerUI().logs.getChildren().add(text);                GameApp.getServerUI().logScroll.setVvalue(1.0);            });        }    }}

pom.xml:

<?xml version="1.0" encoding="UTF-8"?><project xmlns="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 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.project</groupId><artifactId>JavaPong</artifactId><version>1.0-SNAPSHOT</version><name>JavaPong</name><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><junit.version>5.9.1</junit.version>      </properties><dependencies><dependency><groupId>org.openjfx</groupId><artifactId>javafx-controls</artifactId><version>17.0.2</version></dependency><dependency><groupId>org.openjfx</groupId><artifactId>javafx-fxml</artifactId><version>17.0.2</version></dependency><dependency><groupId>org.openjfx</groupId><artifactId>javafx-media</artifactId><version>17.0.2</version></dependency><dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-api</artifactId><version>${junit.version}</version><scope>test</scope></dependency><dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-engine</artifactId><version>${junit.version}</version><scope>test</scope></dependency><dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-core</artifactId><version>2.19.0</version></dependency><dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-core</artifactId><version>2.19.0</version><type>test-jar</type><scope>test</scope></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.10.1</version><configuration><source>17</source><target>17</target></configuration></plugin><plugin><groupId>org.openjfx</groupId><artifactId>javafx-maven-plugin</artifactId><version>0.0.8</version><executions><execution><!-- Default configuration for running with: mvn clean javafx:run --><id>default-cli</id><configuration><mainClass>com.project.javapong/com.project.javapong.GameApp</mainClass><launcher>app</launcher><jlinkZipName>app</jlinkZipName><jlinkImageName>app</jlinkImageName><noManPages>true</noManPages><stripDebug>true</stripDebug><noHeaderFiles>true</noHeaderFiles></configuration></execution></executions></plugin></plugins></build></project>

I have tried different versions of Log4j, changing the pattern format and minimizing the contents of the ServerLog class, but have not found any solution. What should I do to get around this problem?

EDIT: I found that removing the

META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat file from the compiled jar file fixes the problem. However, I'm not sure if this is a good solution and I'm afraid it may cause other problems


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images