Request for assistance in setting up logback.xml #2473
-
Hello all, Here is my logback.xml: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>logs/application.log</file> <!-- Specify the path and filename for your log file -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %msg%n</pattern>
</encoder>
</appender>
<logger name="chapters.configuration" level="INFO" />
<logger name="chapters.configuration.Foo" level="DEBUG" />
<root level="info">
<appender-ref ref="FILE" /> <!-- Add the file appender to the root logger -->
</root>
</configuration> And the maven dependencies: <properties>
<springboot.version>2.7.11</springboot.version>
<sl4j.version>2.0.5</sl4j.version>
<log4j.version>2.20.0</log4j.version>
</properties>
...
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${sl4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${sl4j.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies> And in my codebase I am using the log like this: import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOGGER = LoggerFactory.getLogger(FooBar.class);
LOGGER.info("{} has requested the FooBar command - ENTER.", event.getUser().getName()); and the resulting output will be like this:
Some info about the codebase: Could you please provide me with an example on how to add the timestamps on the logger? I really cannot understand from the documentation what is to be done and all the examples I have tried have no changes at all on the output. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Remove slf4j-simple, it is a separate implementation of the SLF4J API and conflicts with your logback implementation. |
Beta Was this translation helpful? Give feedback.
You should also remove your dependency on slf4j-api since it is incompatible with your implementation version.