log4j multi-threaded log output messed up - Stack Overflow
过去多啦不再A梦2017-05-24 11:35:38
0
1
1352
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
要实现你想要的目的,那要打印控制台日志线程阻塞等待,比如A线程开始执行并打印日志,同时B线程也开始打印输出日志,由于A线程还没执行完,B线程输出内容要等待A线程执行完再输出,万一线程A是个长期运行线程呢? 线程B就不能打印日志了,这样的方案是万万不能接受的
妥协方法:
1 打印日志的LayoutPattern加个%t,输出线程名
2 控制台只输出特定线程
估计这两个方法 都不是题主想要的方法,等高手们看看有什么方法没