I'm using Spring Boot with Log4j with massive parallel computing.
I've using consoleappender to show log message to sysout.
I'm not setting async log4j, so LogManager.shutdown is not allow in this case.
After the program finished successfully, some log were lost(not showed in the console), below is some code/config snippet.
public class TestClass() {
Logger LOGGER = LogManager.getLogger(TestClass.class);
main() {
ExecutorService executorService = Executors.newFixedThreadPool(20);
for(large amount) {
executorService.submit(() -> {
LOGGER.info(".....") // lots of log message inside each task
});
}
executorService.shutdown();
executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
// Thread.sleep(10000) // If main thread sleep for a few seconds, all the log will show in the console.
}
}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO" monitorInterval="5" package="...">
<Properties>
<Property name="application.name">...</Property>
</Properties>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy/MM/dd@HH:mm:ss.SSS} [%t] %-5level %logger{36} ${application.name} %X{X-B3-TraceId} - %msg%n" charset="UTF-8" />
</Console>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="Console" />
</Root>
<Logger name="..." level="DEBUG" additivity="false">
<AppenderRef ref="Console" />
</Logger>
</Loggers>
</Configuration>
My questions are:
Is log4j logger daemon thread for both sync/async? (If yes, can i set it to non-daemon thread?)
How to let my main thread wait util all the log are successfully printed to the console?
Thanks for the help!