Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j - How to log the application name?

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

like image 825
Roxana Avatar asked Sep 03 '25 05:09

Roxana


1 Answers

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

like image 110
Arnaud Avatar answered Sep 04 '25 19:09

Arnaud