I wish I had seen this when you posted it. What you are describing is a non-scalable way for implementing multi-tenant support. You will only be able to deploy a few of these WAR files before you run into resource problems, and if they are byte identical there is no good reason to do it.
When you have multiple WAR files you are effectively trying to have each tenant have its own place in the url path. That is a good thing, but a better way to do it is to have NGINX or the Apache HTTPD server in front of your application. When it inspects the incoming path when it finds the tenant name in the path it replaces that with the generic servlet name and then sets an HTTP header with the tenant name. Then in the application add a servlet filter that converts that header into a ThreadContextMap key/value pair. You can then access the tenant id from anywhere in your application. You can even pass it to downstream services by converting the ThreadContextMap entry back into a header. You can then use the ThreadContextMap value to control a) the names of the log files used if you wish or b) include it as an attribute in every JSON log event when you write to ElasticSerarch. Again - sorry it took me so long to see this. Ralph > On Jan 27, 2026, at 3:01 AM, Christopher Dodunski > <[email protected]> wrote: > > Dear Log4J2 community, > > I am currently exploring the possibility of deploying multiple (byte > identical) WARs for servicing multiple tenants, but hosted by a single Tomcat > installation. > > The WARs, although being identical (including web.xml), are to be named > according to each tenant. My main goal is having these web applications > logging to different files. > > tom.war >> /tom (Tomcat context) >> logs to tom.log > > dick.war >> /dick >> logs to dick.log > > harry.war >> /harry >> logs to harry.log > > I've created separate log4j2.xml configuration files for each and placed > these in WEB-INF, as per below: > > WEB-INF/log4j2-tom.xml > > WEB-INF/log4j2-dick.xml > > WEB-INF/log4j2-harry.xml > > I'd thought that the log4j-web package would allow Log4J to automatically > select the correct XML based on Tomcat context, but this seems not to be the > case. > > I'm eager to learn of a method that would allow log filenames to be set from > outside the WAR, if possible. > > Thanking you in advance for any suggestions. > > Kind regards, > > Chris. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
