log4j multi-threaded log output messed up - Stack Overflow
过去多啦不再A梦2017-05-24 11:35:38
0
1
1550
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
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
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