Win a copy of Kotlin for Android App Development this week in the Kotlin 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
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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:
 
The problems of the world fade way as you eat a piece of pie. This tiny ad has never known problems:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!