• 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
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

log4j help needed  RSS feed

 
Ranch Hand
Posts: 431
  • Mark post as helpful
  • send pies
  • 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
  • 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:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!