Re: Configuring log filenames in a multi-tenant, identical-WAR scenario

Ralph Goers <[email protected]> Fri, 5 Jun 2026 17:08:22 -0700
Newsgroups gmane.comp.jakarta.log4j.user
Message-ID <[email protected]>
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=E2=80=AFAM, Christopher Dodunski =
<[email protected]> wrote:
>=20
> Dear Log4J2 community,
>=20
> I am currently exploring the possibility of deploying multiple (byte =
identical) WARs for servicing multiple tenants, but hosted by a single =
Tomcat installation.
>=20
> 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.
>=20
>    tom.war >> /tom (Tomcat context) >> logs to tom.log
>=20
>    dick.war >> /dick >> logs to dick.log
>=20
>    harry.war >> /harry >> logs to harry.log
>=20
> I've created separate log4j2.xml configuration files for each and =
placed these in WEB-INF, as per below:
>=20
>    WEB-INF/log4j2-tom.xml
>=20
>    WEB-INF/log4j2-dick.xml
>=20
>    WEB-INF/log4j2-harry.xml
>=20
> 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.
>=20
> I'm eager to learn of a method that would allow log filenames to be =
set from outside the WAR, if possible.
>=20
> Thanking you in advance for any suggestions.
>=20
> Kind regards,
>=20
> Chris.
>=20
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>=20