'Logs are not getting generated with slf4j
I started facing issue since I have upgraded to 2.17.1 version , earlier my version was 2.1 and everything is working properly , since i have upgraded the version logs are not getting generated to log file
I have following configuration in my pom.xml
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>2.0.0-alpha6</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.1</version>
</dependency>
My logback.xml has following content:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="MyApp" packages="">
<Appenders>
<RollingRandomAccessFile name="RollingRandomAccessFile" fileName="/lcc/lccapp/logs/lcc-publisher/producer.log"
filePattern="/lcc/lccapp/logs/lcc-publisher/producer-%d{MM-dd-yyyy}-%i.zip" immediateFlush="false">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" />
</Policies>
<DefaultRolloverStrategy max="100"/>
</RollingRandomAccessFile>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="RollingRandomAccessFile"/>
</Root>
</Loggers>
</Configuration>
What i see in boot.log is:
Starting the lcc-publisher application
Application directory is /lcc/lccapp/apps/lcc-publisher
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#noProviders for further details.
SLF4J: Class path contains SLF4J bindings targeting slf4j-api versions prior to 1.8.
SLF4J: Ignoring binding found at [jar:file:/lcc/lccapp/apps/lcc-publisher/lib/log4j-slf4j-impl-2.17.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#ignoredBindings for an explanation.
Current dir using System:/lcc/lccapp/apps/tcc-publisher
Application is running without any issues , but logs are not getting written to log files.
Solution 1:[1]
Have you seen this page? Log4j 2 SLF4J Binding. Starting with Log4J 2.11.1, there are two separate implementations of Log4J 2's SLF4J binding, depending on your version of SLF4J.
Your use of log4j-over-slf4j version 2.0.0-alpha6 means your SLF4J API version (slf4j-api) is also 2.0.0-alpha6. Thus, according to the link above, you need to change your use of log4j-slf4j-impl to log4j-slf4j18-impl.
A couple of other things about the SLF4J version you're using:
- Are you sure you want to use SLF4J 2.x instead of 1.x? The fact that they are shipping a 2.x implies there are breaking changes in the API. So I don't think it can be guaranteed that any current version of Log4J is going to be compatible, especially since it's not finalized. 2.0.0 is still shipping alpha versions.
- Are you sure you want to use an alpha version of SLF4J instead of a stable release? Whatever works right now, it may break next time someone upgrades your SLF4J.
Incidentally, log4j-slf4j-impl brings in log4j-api transitively, so you should not need to explicitly declare log4j-api as a dependency. This is one fewer entry you need to manually maintain, and one fewer <version></version> you have to worry about keeping in sync.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
