×

Loading...
Ad by
  • 技多不压身,工到自然成:安省技工证书特训班,点击咨询报名!
Ad by
  • 技多不压身,工到自然成:安省技工证书特训班,点击咨询报名!

How to ues log4j to send log email in the multithreaded processes as similiar with single-threaded

My current system is single-threaded with several modules which are
processed in sequence. I use SMTPAppender to capture error and send warning
emails with the following format:
[time][thread-1][module 1]start: XXXXXXX
[time][thread-1][module 2]XXXXXXX
[time][thread-1][module 3]XXXXXXX
[time][thread-1][module 4]ERR: XXXXXXX


After I change the system to multhithreaded, the logs will be tangled up
like:
[time][thread-1][module 1]start: XXXXXXX
[time][thread-2][module 1]start: XXXXXXX
[time][thread-1][module 2]XXXXXXX
[time][thread-1][module 3]XXXXXXX
[time][thread-2][module 2]XXXXXXX
[time][thread-2][module 3]XXXXXXX
[time][thread-2][module 4]end: XXXXXXX
[time][thread-1][module 4]ERR: XXXXXXX
.....

Moreover, if the buffer size in SMTPAppender is set as small, some reference
info about thread-1 will be filtered. Is there any way to format the log
email in the multhithreaded processes as similiar with single-threaded?
Customize the SMTPAppender? Or create Logger per thread?
Report