When an application calls LogManager.getLogger() Log4j uses a ContextSelector 
to locate the appropriate LoggerContext. The default is the 
ClassLoaderContextSelector, which will use the LoggerContext associated with 
the ClassLoader of the class obtaining the Logger.

To do what you want you would need to create a new ContextSelector that can 
differentiate when it should use one LoggerContext over another. You would also 
need. To be sure that when each loads its configuration that it somehow can 
determine which configuration it should use.

Ralph

> On May 27, 2020, at 5:59 AM, CARTEREAU Benjamin <benjamin.carter...@cnav.fr> 
> wrote:
> 
> Hello,
> I am using log4j2 in a less common environment (webMethods IS java server).
> 
> The thing is that there is a common service that do the logging (using 
> log4j2) for different "applications" (called "package" in that environment) 
> within the same server.
> 
> I would like to know if there is a way, within the same common service/java 
> code to initialize a different LoggerContext for each application and using a 
> different "log4j2.xml" configuration file (these configuration files could 
> use a different name "log4j2-A. xml", "log4j2-B. xml" or be put in different 
> directories).
> 
> I have been trying to use:
> LoggerContext contextA = Configurator.initialize(pkg, 
> ClassLoader.getSystemClassLoader(), "log4j2-A.xml");
> But when trying then to create a new context :
> LoggerContext contextB = Configurator.initialize(pkg, 
> ClassLoader.getSystemClassLoader(), "log4j2-B.xml");
> But without success. I get the message :
> WARN locateContext called with URI log4j2-B.xml. Existing LoggerContext has 
> URI log4j2-A.xml
> 
> I would guess it is the expected behavior since I am using the defaut 
> ContextSelector (ClassLoaderContextSelector) and I can only have one context 
> (and one configuration file eventually).
> Am I right ?
> Or is there a way to achieve what I am looking for ?
> 
> Best regards.
> 
> Ben
> *****************************************************************************************
>  Ce message ?lectronique, les ?ventuels fichiers joints et les informations 
> qu'il contient, peuvent ?tre couverts par le secret professionnel et sont 
> exclusivement adress?s ? son destinataire. Si vous le recevez par erreur, 
> merci d'en informer l'exp?diteur et de le d?truire. A ce titre, toute 
> diffusion non autoris?e de ce message, m?me partielle, sous quelque forme que 
> ce soit, est interdite et punie par la loi. En aucun cas, le contenu de ce 
> message ne peut valoir offre ou acceptation ou engagement de la part de la 
> CNAV. Les opinions contenues dans ce message sont personnelles ? l'?metteur. 
> Il est de la responsabilit? du destinataire de s'assurer que le message et 
> ses ?ventuelles pi?ces jointes ne contiennent pas de virus informatique.



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org

Reply via email to