Redian新闻
>
How to ues log4j to send log email in the multithreaded processes as similiar with single-threaded
avatar
How to ues log4j to send log email in the multithreaded processes as similiar with single-threaded# Java - 爪哇娇娃
l*b
1
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
avatar
g*g
2
You either create logger per thread, or maybe extend SMTPAppender and
filter the log the way you want.

warning

【在 l*****b 的大作中提到】
: 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

avatar
l*b
3
Thanks, goodbug. Those are good advice. I have some questions on them:
For logger per thread, will it impact the performance? Provided thread pool
max is 200, there are about 200 logger at some time.
For customed SMTPAppender, how many buffer should I set? If threads
increased, it has chance the fixed buffer cannot reach the first log entry.
avatar
A*o
4
question: how do you capture error and remembers the previous log event?
or how many emails you receive in the single thread mode in your example?

warning

【在 l*****b 的大作中提到】
: 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

avatar
l*b
5
Hi,Amao, I use SMTPAppender. It has a buffer setting to record specific
number of log events. My setting in single thread mode is 10. When error
occurs, one email is send out with 10 events.
avatar
A*o
6
thanks for explaining. but i doubt the logger per thread
model would work without make your own extentions.
anyway, i don't think your request is what log4j intends to do.
and from my experience, tempering with log4j other than config is not worthy.
how about dump everything into a db using jdbc appender,
and assign each thread with a uid and log it.
and when an error occurs,
dig the db, and query on the uid, and send your email?

【在 l*****b 的大作中提到】
: Hi,Amao, I use SMTPAppender. It has a buffer setting to record specific
: number of log events. My setting in single thread mode is 10. When error
: occurs, one email is send out with 10 events.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。