BAEL-5124 - Adding a module with examples of printing thread info in the log file using log4j (#11704)
* adding a example module for printing thread info in log file using log4j * - fix: removing submodule * - fix: Adding submodule * - fix: Removing `.gitignore`, `README.md`, and `application.properties`. - fix: Removing Spring boot and adding log4j2 from Maven Central * - fix: Changing module name as suggested to log4j2-thread-info. - fix: Fixing log path in log4j2 configuration * - feat: Removing log4j2-thread-info module - feat: Adding example code into existing log4j2 module * - fix: Removing unnecessary logging * - fix: Separating thread info in the logging pattern * - fix: package name to lowercase * lowercasing package name and variable name * changing package name in configuration * - fix: formatting * - fix: formatting imports
This commit is contained in:
parent
dbdb4ccade
commit
b97323ea90
|
@ -0,0 +1,18 @@
|
|||
package com.baeldung.logging.log4j2threadinfo;
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class Log4j2ThreadInfo {
|
||||
private static final Logger logger = LogManager.getLogger(Log4j2ThreadInfo.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
IntStream.range(0, 5).forEach(i -> {
|
||||
Runnable runnable = () -> logger.info("Logging info");
|
||||
Thread thread = new Thread(runnable);
|
||||
thread.start();
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration>
|
||||
<Properties>
|
||||
<Property name="LOG_PATTERN">
|
||||
%d{yyyy-MM-dd HH:mm:ss.SSS} --- thread_id="%tid" thread_name="%tn" thread_priority="%tp" --- [%p] %m%n
|
||||
</Property>
|
||||
</Properties>
|
||||
<Appenders>
|
||||
<RollingFile name="RollingName" filename="logs/app.log"
|
||||
filePattern="$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log">
|
||||
<PatternLayout>
|
||||
<Pattern>${LOG_PATTERN}</Pattern>
|
||||
</PatternLayout>
|
||||
<Policies>
|
||||
<SizeBasedTriggeringPolicy size="20MB"/>
|
||||
</Policies>
|
||||
</RollingFile>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Logger name="com.baeldung.logging.log4j2threadinfo" level="trace">
|
||||
<AppenderRef ref="Console"/>
|
||||
</Logger>
|
||||
<Root level="error">
|
||||
<AppenderRef ref="RollingName"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
Loading…
Reference in New Issue