Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

log4j help needed

 
Ranch Hand
Posts: 431
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi friends,

In my project log4j is used extensively. Almost in all the action classes (we use struts), we log things. But the problem is, when concurrent users are there the logs are getting mixed up. Because of this debugging becomes a head-ache. I want to prefix all the logging statments with the userid of the person who has logged in. But its not possible to do this change in all the places where logging is used since I need to compile and deploy the whole application again which is impossible. Is there any way by which I can change some class or config file through which I can achieve my requirement?
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can achieve this through some code and through some configuration. Have a look at the NDC/MDC section at:

Log4j article
Log4j MDC article

You will find a code sample(MDCUserServletFilter.java) at:
Code sample

Your log4j.xml will look like:
 
If you look closely at this tiny ad, you will see five bicycles and a naked woman:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic