search

Home  >  Q&A  >  body text

log4j multi-threaded log output messed up - Stack Overflow

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

过去多啦不再A梦过去多啦不再A梦2766 days ago1558

reply all(1)I'll reply

  • 怪我咯

    怪我咯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

    reply
    0
  • Cancelreply