problem
When using maven-shade-plugin or maven-assembly-plugin to mark the project into an executable JAR package, if you import log4j2, the following problems will occur:
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.
Solution
Add the following configuration to pom.
< plugin > < groupId > org.apache.maven.plugins </ groupId > < artifactId > maven-shade-plugin </ artifactId > < version > 2.4.3 </ version > < executions > < execution > < phase > package < / phase > < goals > < goal > shade </ goal > </ goals > <configuration > < filters > < filter > < artifact > *:* </ artifact > < excludes > < exclude > META-INF/*.SF </ exclude > < exclude > META-INF/*.DSA </ exclude > < exclude > META-INF/*.RSA </ exclude > </ excludes > </ filter > </ filters > <finalName> ${artifactId}-${env}-${version} </ finalName > < transformers > < transformer implementation ="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" > < mainClass > xxx.yyyy.zzz .Main </ mainClass > </ transformer > < transformer implementation ="org.apache.maven.plugins.shade.resource.AppendingTransformer" > < resource > META-INF/spring.handlers </ resource > </transformer > < transformer implementation ="org.apache.maven.plugins.shade.resource.AppendingTransformer" > < resource > META-INF/spring.schemas </ resource > </ transformer > < transformer implementation ="org.apache.maven .plugins.shade.resource.AppendingTransformer" > < resource > META-INF/spring.tooling </ resource > </ transformer > < transformer implementation="org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer" /> < transformer implementation ="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> < transformer implementation ="com.github.edwgiz. mavenShadePlugin.log4j2CacheTransformer.PluginsCacheFileTransformer" /> </ transformers > </ configuration > </ execution > </ executions > < dependencies > < dependency > <groupId >com.github.edwgiz </ groupId > < artifactId > maven-shade-plugin.log4j2-cachefile-transformer </ artifactId > < version > 2.6.1 </ version > </ dependency > </ dependencies > </ plugin >
Cause Analysis
log4j2 is plug-in programming. When the log4j2 package is compiled, or the package containing the log4j2 plug-in is compiled, the plug-in information that needs to be loaded will be placed in META-INF/org/apache/logging/log4j/core/config/plugins/ Log4j2Plugins.dat (including the official logj42 native plug-in), and then when the project starts, log4j2 will scan the plug-in information file in the META-INF directory of each jar package, and then load the plug-in.
But when the project is marked as a jar package, if there are Log4j2Plugins.dat files in two different jar packages, there will be a problem, one of the files will be overwritten by the other, resulting in a file when the project starts The plug-in cannot be loaded normally, resulting in an error.
To solve this problem, when all jar packages are labeled as one jar package, the Log4j2Plugins.dat in each jar package needs to be merged. This is what the maven-shade-plugin.log4j2-cachefile-transformer package does.
Read More:
My maven dependency:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-log4j2</artifactId>
<version>1.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.8.0-beta4</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j18-impl</artifactId>
<version>2.14.0</version>
</dependency>
example Java code:
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.SNSEvent;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class LogTest implements RequestHandler<SNSEvent, String> {
@Override
public String handleRequest(SNSEvent snsEvent, Context context) {
log.trace("This is trace");
log.debug("This is debug");
log.info("This is info");
log.warn("This is warn");
log.error("This is error");
return "logged";
}
}
my log4j2.xml:
<Configuration status="WARN">
<Appenders>
<Lambda name="Lambda">
<PatternLayout>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %X{AWSRequestId} %-5p %c{1} - %m%n</pattern>
</PatternLayout>
</Lambda>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Lambda" />
</Root>
</Loggers>
</Configuration>
After deploy to lambda, invoke the lambda and the logs in CloudWatch will be:
2021-03-05T16:32:12.336-05:00 | WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.
-- | --
| 2021-03-05T16:32:12.484-05:00 | ERROR StatusLogger Unrecognized format specifier [d]
| 2021-03-05T16:32:12.484-05:00 | ERROR StatusLogger Unrecognized conversion specifier [d] starting at position 16 in conversion pattern.
| 2021-03-05T16:32:12.485-05:00 | ERROR StatusLogger Unrecognized format specifier [thread]
| 2021-03-05T16:32:12.486-05:00 | ERROR StatusLogger Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern.
| 2021-03-05T16:32:12.486-05:00 | ERROR StatusLogger Unrecognized format specifier [level]
| 2021-03-05T16:32:12.486-05:00 | ERROR StatusLogger Unrecognized conversion specifier [level] starting at position 35 in conversion pattern.
| 2021-03-05T16:32:12.486-05:00 | ERROR StatusLogger Unrecognized format specifier [logger]
| 2021-03-05T16:32:12.486-05:00 | ERROR StatusLogger Unrecognized conversion specifier [logger] starting at position 47 in conversion pattern.
| 2021-03-05T16:32:12.486-05:00 | ERROR StatusLogger Unrecognized format specifier [msg]
| 2021-03-05T16:32:12.487-05:00 | ERROR StatusLogger Unrecognized conversion specifier [msg] starting at position 54 in conversion pattern.
| 2021-03-05T16:32:12.487-05:00 | ERROR StatusLogger Unrecognized format specifier [n]
| 2021-03-05T16:32:12.487-05:00 | ERROR StatusLogger Unrecognized conversion specifier [n] starting at position 56 in conversion pattern.
| 2021-03-05T16:32:12.512-05:00 | ERROR StatusLogger Unrecognized format specifier [d]
| 2021-03-05T16:32:12.512-05:00 | ERROR StatusLogger Unrecognized conversion specifier [d] starting at position 16 in conversion pattern.
| 2021-03-05T16:32:12.512-05:00 | ERROR StatusLogger Unrecognized format specifier [thread]
| 2021-03-05T16:32:12.513-05:00 | ERROR StatusLogger Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern.
| 2021-03-05T16:32:12.513-05:00 | ERROR StatusLogger Unrecognized format specifier [level]
| 2021-03-05T16:32:12.513-05:00 | ERROR StatusLogger Unrecognized conversion specifier [level] starting at position 35 in conversion pattern.
| 2021-03-05T16:32:12.513-05:00 | ERROR StatusLogger Unrecognized format specifier [logger]
| 2021-03-05T16:32:12.514-05:00 | ERROR StatusLogger Unrecognized conversion specifier [logger] starting at position 47 in conversion pattern.
| 2021-03-05T16:32:12.514-05:00 | ERROR StatusLogger Unrecognized format specifier [msg]
| 2021-03-05T16:32:12.514-05:00 | ERROR StatusLogger Unrecognized conversion specifier [msg] starting at position 54 in conversion pattern.
| 2021-03-05T16:32:12.514-05:00 | ERROR StatusLogger Unrecognized format specifier [n]
| 2021-03-05T16:32:12.514-05:00 | ERROR StatusLogger Unrecognized conversion specifier [n] starting at position 56 in conversion pattern.
| 2021-03-05T16:32:13.007-05:00 | START RequestId: c2f5eb6d-4c51-4833-9663-6b37e6cc9aaf Version: $LATEST
| 2021-03-05T16:32:13.248-05:00 | END RequestId: c2f5eb6d-4c51-4833-9663-6b37e6cc9aaf
If I remove aws-lambda-java-log4j2
and change appender to a Console appender, the log will back to normal behavior.
Issue
Spring 4.3.30+hibernate 5 application. pom.xml has all the log4j2 dependencies.
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>${log4j2.version}</version>
</dependency>
even added log4j2.xml
<?xml version="1.0" encoding="UTF-8" ?>
<Configuration status="TRACE">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%p [%t] %c{1}.%M(%L) | %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
The ERROR i have been getting:
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.
What else am i missing here as i keep getting above error even though my pattern doesn’t contain the default layout?
I was using log4j before migrating to log4j2.Din’t plan on migrating to log4j2 but as i had to upgrade spring and hibernate i started getting ERROR StatusLogger No Log4j2 configuration file found. That’s when i decided to migrate to log4j2.
Solution
First, lets list your dependencies and what they do:
- log4j-jcl provides an implementation for Apache Commons Logging to route those logging calls to Log4j 2.
- log4j-core is the Log4j 2 implementation.
- log4j-slf4j-impl routes logging calls using the SLF4J API to Log4j 2.
- log4j-api is the Log4j 2 API.
- log4j-1.2-api routes logging calls made using log4j 1.x to Log4j 2.
- log4j-to-slf4j routes logging calls from the Log4j 2 API to SLF4J.
In case it isn’t clear from the descriptions, item 6 is going to be a problem. First, you now have 2 implementations of the Log4j 2 API — log4j-core and log4j-to-slf4j. If log4j-to-slf4j were the one to «win» you would end up with logging going nowhere as the calls would bounce between Log4j and SLF4J and back again.
However, if these are in your dependencyManagement section of the the pom that would be a different story as all that does is declare which version of the jars you want to use.
As for the errors you are seeing, that happens because Log4j’s core plugins aren’t being loaded for some reason. That can happen if you are shading everything into a single jar and didn’t include Log4j’s Log4jPlugins.dat file.
Answered By — rgoers
Hi,
I wanted to start Minecraft server 1.13.2 — downloaded from official website.
After start with:
java -Xmx1024M -Xms1024M -jar c:!ServerMinecraftJavaserver.jar nogui
I received errors like below:
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 No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'org.apache.logging.log4j.simplelog.StatusLogger.level' to TRACE to show Log4j2 internal initialization logging. 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.
What I can do with this error?
Already my Java in the latest version. I tried to start it on Win7 and WinServer — same result.
i was making before my own server without any problems.
Also I found that I need to delete one file in .jar file — but this file is not existing there.
Please help
Best regards
I’ve just changed on my project all log4j maven artifacts from 2.0.2 -> 2.1. When I deployed and started it on the Amazon EC2 Server got the following errors:
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 No log4j2 configuration file found. Using default configuration: logging only errors to the console.
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.
I’ve nailed it down that it comes from the log4j-slfj-impl change. It is not major, since downgrading this artifact to 2.0.2 work just fine, but might be worth looking at.
openjdk version «1.8.0_242»
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
:/home/container$ java -Xms128M -Xmx4096M -jar server.jar
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 No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property ‘org.apache.logging.log4j.simplelog.StatusLogger.level’ to TRACE to show Log4j2 internal initialization logging.
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.
[Hosting-Minecraft.com] Статус сервера изменён на ВЫКЛЮЧЕН
%d [%thread] %-5level %logger — %msg%nException in thread «main»
Сервер если что 1.12.2 с модами
harlins 2 / 2 / 3 Регистрация: 22.10.2013 Сообщений: 41 |
||||||||
1 |
||||||||
14.02.2016, 00:33. Показов 8535. Ответов 4 Метки нет (Все метки)
Ребята перешел к изучению логирования в java. Остановился на log4j
Вот код тестового класса
Но при запуске в консоль валит ошибку Добавлено через 3 минуты
__________________
0 |
Programming Эксперт 94731 / 64177 / 26122 Регистрация: 12.04.2006 Сообщений: 116,782 |
14.02.2016, 00:33 |
4 |
39 / 28 / 8 Регистрация: 14.04.2012 Сообщений: 249 |
|
21.08.2016, 16:43 |
2 |
а без мавен можно как-то настроить?
0 |
4087 / 3821 / 745 Регистрация: 18.05.2010 Сообщений: 9,331 Записей в блоге: 11 |
|
21.08.2016, 18:29 |
3 |
а без мавен можно как-то настроить? Можно. Главное положить файл log4j2.xml в папку, которая попадёт в classpath приложения при запуске.
у меня просит slf4j? Кто просит?
0 |
942 / 686 / 229 Регистрация: 28.04.2013 Сообщений: 1,924 |
|
21.08.2016, 18:34 |
4 |
Остановился на log4j Первый?
Создал конфигурационный файл log4j2.xml Где создал? Если log4j первый используете, то имя файла не верное.
0 |
kostrorod 39 / 28 / 8 Регистрация: 14.04.2012 Сообщений: 249 |
||||||||
21.08.2016, 22:06 |
5 |
|||||||
log4j2.xml положил в src Файл видит в idea ошибки пишет норм в консоль и файл. Кликните здесь для просмотра всего текста
log4j2.xml Кликните здесь для просмотра всего текста
Добавлено через 2 часа 36 минут
0 |