Is there a reason you didn’t use one of the Configurator.initialize() methods?
Ralph
> On Aug 25, 2017, at 2:17 AM, Darlea, Radu <radu.dar...@finastra.com> wrote:
>
> Answering myself:
> The only solution I found by successive tries was to give up using the web
> app style of integrating log4j2 and do it as in a standalone app.
> 1. I removed log4j-web jar
> 2. I removed any listener and servlet and parameter from web.xml
> regarding log4j2
> 3. I placed the log4j2.xml in classes (otherwise I found no way to
> avoid the error message No log4j2 configuration file found)
> 4. I removed any static initialization of logger in the listeners
> listed in web.xml
> 5. I change the code somehow similar to app initialization
>
> System.setProperty("FTMIDDLE_LOGDIR", fullPathLogDir.toString());
> // start and configure the logger
> LoggerContext context =
> ((LoggerContext)org.apache.logging.log4j.LogManager.getContext(false));
> // just for debugging
> Configuration log4jConfiguration = context.getConfiguration();
> getLogger().info("Finished configuring log4j. The configuration file is: "
> + context.getConfigLocation()
> + "\nThe configuration details are: \n[appender : "
> + log4jConfiguration.getAppenders().toString() + "]"
> + "\n[loggers : " + log4jConfiguration.getLoggers().toString() + "]");
>
> This is the only line that matters LoggerContext context =
> ((LoggerContext)org.apache.logging.log4j.LogManager.getContext(false));
>
> After it, the loggers get correctly initialized, including in the servlet
> listeners
> private static Logger logger = null;
> private static Logger getLogger() {
> if (logger == null) {
> logger = LogManager.getLogger(ContextListener.class);
> }
> return logger;
> }
>
> I am not happy with this approach, but at least appears to be fine
> functionally.
>
> Thx, Radu
> Ext. 22912
> Mobile + (40)7405 71909
> Advance notice of absence July 6th, 7th; July 24th to August 4th
>
> From: Darlea, Radu
> Sent: Monday, August 21, 2017 10:32 AM
> To: log4j-user@logging.apache.org
> Subject: RE: Log4j2 - setting programatically the env variable
>
> Hi
>
> Anyone having a clue, please?
>
> Thx, Radu
>
> From: Darlea, Radu
> Sent: Thursday, August 17, 2017 6:10 PM
> To: log4j-user@logging.apache.org <mailto:log4j-user@logging.apache.org>
> Subject: Log4j2 - setting programatically the env variable
>
> Hi
>
> Please find the snippet of web.xml
>
>
>
> http://java.sun.com/xml/ns/javaee
> <http://java.sun.com/xml/ns/javaee>"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
> <http://www.w3.org/2001/XMLSchema-instance>"
> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd
> <http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd>"
> version="3.0">
>
> ft-middle
>
> isLog4jAutoInitializationDisabled
> true
>
>
>
> summit.feserver.ContextListener
>
>
>
>
> MessageHandler
> summit.feserver.MessageHandlerServlet
>
> packet_size
> 1024
> Specify response packet size, in unit of
> KB
>
>
>
>
>
> Please find the deployed libraries
> juli-6.0.16.jar
> juli-LICENSE.txt
> log4j-1.2-api-2.8.2.jar
> log4j-api-2.8.2.jar
> log4j-core-2.8.2.jar
> log4j-web-2.8.2.jar
> in Tomcat 8.5.20
>
> Please find the log4j2 configuration saved as log4j2.xml in
> tomcat\webapps\ft_middle_ws\WEB-INF
>
>
>
>
> fileName="${sys:FTMIDDLE_LOGDIR}/FTMiddle.log"
> filePattern="${sys:FTMIDDLE_LOGDIR}/FTMiddle-%d{-MM-dd}.log">
>
>
> [%-5level] %d{-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
>
>
>
>
>
>
>
>
> pattern="[%-5level] %d{-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" />
>
>
>
>