log4j multi-threaded log output is confusing. How to solve this? It is said on the Internet that an output file is defined according to different threads, but I want to output them separately on the console.
How to
become
so
怪我咯2017-05-24 11:37:38
To achieve what you want, you need to print the console log and the thread is blocked and waiting. For example, thread A starts executing and printing the log, and thread B also starts printing the output log. Since thread A has not finished executing, the output content of thread B needs to Wait for thread A to finish executing before outputting. What if thread A is a long-running thread? Thread B cannot print logs. This solution is absolutely unacceptable
Compromise method:
1. Add %t to the LayoutPattern of the printed log and output the thread name
2. The console only outputs specific threads
It is estimated that both methods This is not the method that the questioner wants. Let’s wait for the experts to see if there is any method