• 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

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:
reply
    Bookmark Topic Watch Topic
  • New Topic