I was wondering is there any way for use Tinylog with app which is requiring Log4J2 implementation. (adapter or something)
Asked
Active
Viewed 171 times
1 Answers
0
If I understand your question correctly, you want to use the tinylog 2 API with an Apache Log4j 2 logging back-end. You can do that by using JBoss logging as an adapter between both.
Required dependencies:
<dependency>
<groupId>org.tinylog</groupId>
<artifactId>tinylog-api</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.tinylog</groupId>
<artifactId>tinylog-jboss</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>3.4.1.Final</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-core</artifactId>
<version>2.14.0</version>
</dependency>
Example Application:
import org.apache.logging.log4j.LogManager;
import org.tinylog.Logger;
public class Application {
public static void main(String[] args) {
Logger.info("Greetings from tinylog!");
LogManager.getLogger().info("Greetings from Apache Log4j 2!");
}
}
Example Log4j configuration (nothing special):
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="ConsoleAppender" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %logger %level: %msg%n" />
</Console>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="ConsoleAppender" />
</Root>
</Loggers>
</Configuration>
Output on my computer:
21:01:27.367 [main] Application INFO: Greetings from tinylog!
21:01:27.368 [main] Application INFO: Greetings from Apache Log4j 2!

Martin
- 598
- 1
- 4
- 27