• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will need one SMTPAppender per thread if that's the way you want to see the output.
 
Sky Loi
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, thank you for your quick advice, Paul.

Do you mean I need to create Logger per thread as well? So far, my Logger is implemented as singleton and shared by threads. The following is my assumption:

Module 1: new Logger and new SMTPAppender as non-singleton; pass the Logger reference to Module 2 ....
Module 2: use the same Logger; pass the Logger reference to Module 3 ....
....


 
Sky Loi
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dose it has performance issue if creating new logger instance per thread?

And is there any suggestion how to save the logger instance to be shared by modules? I want to use a concurrent hashmap to store the logger by thread ID. Is it good?
 
Let nothing stop you! Not even this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic