• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

LOG4J Appending Username in log

 
Karthikeyan Ganapathy
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just want to know how to append a String in a log using Log4j, in my application we have multiple users, so i just want to append the Username along with the log, so that i can differentiate the logs based on the user, Help me in find out how to append the username along with logs, not through each and every class, should be at some log4j class
 
Guillaume Jourdan
Ranch Hand
Posts: 47
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the log4J mapped diagnostic context (MDC)

You can define the username in your user thread code :



And add it in your appender pattern configuration, example :



Warning :

MDC Javadoc wrote:The MDC is managed on a per thread basis. A child thread automatically inherits a copy of the mapped diagnostic context of its parent.


Regards,

Guillaume.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic