Reputation: 1581
I have a shared log4j configuration between multiple web applications deployed in tomcat. Is there any log4j workaround available to log the app name that triggered the log? (Some of the apps have classes with same packages,same methods, and I want to distinguish somehow between them)
Thanks
Upvotes: 4
Views: 3534
Reputation: 17534
You may use the Mapped Diagnostic Context
Your java code may set custom values like :
MDC.put("applicationName", "Application12");
And your logger's pattern would use the X% system for the custom data :
%X{applicationName}
As you seem to be using web applications, this should take place in a Servlet Filter (which will clean the values once doFilter
is done), have a look at this topic :
Logging user activity in web app
Upvotes: 2