File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Open Source Projects and the fly likes LOG4J Appending Username in log Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "LOG4J Appending Username in log" Watch "LOG4J Appending Username in log" New topic
Author

LOG4J Appending Username in log

Karthikeyan Ganapathy
Greenhorn

Joined: May 12, 2012
Posts: 1
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

Joined: Jul 24, 2012
Posts: 47

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: LOG4J Appending Username in log