Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming 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
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Question about log4J

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering if it is possible to associate a login user ID with each log message (in a web based system). I want to record what a user does(e.g. post a message, view/update a record ...).
Regards,
Jason
 
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We did something similar at my last job by wrapping the Logger (formerly Category) class in a wrapper that was used to perform all logging in the web app. Once you do that, you pretty much have control over all logging activities.
hth,
bear
 
Jason Wang
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply but I still can't figure out how to associate the userID into Logger object created in servlet, java bean, helper class and etc. Thanks.
Jason
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think log4j would have any web-specific code in it, which is what you want (you want an output format that includes information from an HttpSession, yes?)
Seems to me you could extend the PatternLayout to add something for user... I don't know if this has been done already by someone else, have a look at the log4j mailing lists.
 
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!