Return-Path: X-Original-To: apmail-logging-log4j-dev-archive@www.apache.org Delivered-To: apmail-logging-log4j-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1B46317C81 for ; Wed, 10 Jun 2015 16:01:02 +0000 (UTC) Received: (qmail 34359 invoked by uid 500); 10 Jun 2015 16:01:02 -0000 Delivered-To: apmail-logging-log4j-dev-archive@logging.apache.org Received: (qmail 34318 invoked by uid 500); 10 Jun 2015 16:01:01 -0000 Mailing-List: contact log4j-dev-help@logging.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Log4J Developers List" Reply-To: "Log4J Developers List" Delivered-To: mailing list log4j-dev@logging.apache.org Received: (qmail 34308 invoked by uid 99); 10 Jun 2015 16:01:01 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Jun 2015 16:01:01 +0000 Date: Wed, 10 Jun 2015 16:01:01 +0000 (UTC) From: =?utf-8?Q?G=C3=BCnter_Albrecht_=28JIRA=29?= To: log4j-dev@logging.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (LOG4J2-1045) WAS8: externalize log4j2.xml via URL resource MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/LOG4J2-1045?page=3Dcom.atlassia= n.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D145= 78624#comment-14578624 ]=20 G=C3=BCnter Albrecht edited comment on LOG4J2-1045 at 6/10/15 4:00 PM: ------------------------------------------------------------------ We are using Web applications (w/ {{web.xml}}) and pure EJB applications (w= /o {{web.xml}}). Why should I use the log4j-web module in an EJB app? And what does it mean ??each EJBs initialization call Configurator.initiall= ze() ...have their own configuration??? We need one configuration per app not per EJB. Besides, when and where to call {{Configurator.initiallze()}} is not mentio= ned in the official Log4j2 documentation - stackoverflow.com mentions it at= least. And how will you ??set log4j.configurationFile to the URL you want to use??= ?=20 Remember the URL must be set dynamically per app meaning via a lookup to a = URL resource of WAS8 - neither hard coded in your app nor via a system prop= erty which has server scope. In a *Web app* I defined {{MyConfiguartionFactory}} and in the constructor = I'm calling {{Configurator.initiallze()}} where the last argument is the UR= I to the value of my URL resource defined in WebSphere. I used {{MyConfigua= rtionFactory}} by setting the property {{log4j.configurationFactory}} in {{= log4j2.component.properties}} - this works fine. Then I tried to use the same {{MyConfiguartionFactory}} in {{log4j2.compone= nt.properties}} in a *pure EJB app* (Singleton Startup Bean and several oth= er EJB SLSBs). There this solution fails. The log trace shows that first my= configuration with my URL resource started successfully but immediately af= ter that it's stopped automatically and replaced by a second start of a def= ault configuration which fails that way that it cannot find any {{log4j2.xm= l}} saying only ERRORs and FATALs are logged to console. {panel:title=3DLog4j2 Trace |borderStyle=3Ddashed|borderColor=3D#ccc|titleB= GColor=3D#1E90FF|bgColor=3D#F4F4F4}DEBUG Starting configuration XmlConfigur= ation[location=3DD:\logs\log4j2.xml] ... INFO Log4j appears to be running in a Servlet environment, but there's no l= og4j-web module available. If you want better web container support, please= add the log4j-web JAR to your web archive or server lib directory. ... DEBUG Started configuration XmlConfiguration[location=3DD:\logs\log4j2.xml]= OK. TRACE Stopping org.apache.logging.log4j.core.config.DefaultConfiguration@cd= 868062... TRACE AbstractConfiguration stopped 0 AsyncLoggerConfigs. TRACE AbstractConfiguration stopped 0 AsyncAppenders. TRACE AbstractConfiguration stopped 1 Appenders. TRACE AbstractConfiguration stopped 0 Loggers. DEBUG Stopped org.apache.logging.log4j.core.config.DefaultConfiguration@cd8= 68062 OK ... DEBUG Reconfiguration complete for context[name=3D-578826301] at file:D:/lo= gs/log4j2.xml (org.apache.logging.log4j.core.LoggerContext@86474db1) with o= ptional ClassLoader: null DEBUG PluginManager 'ConfigurationFactory' found 3 plugins INFO Log4j appears to be running in a Servlet environment, but there's no l= og4j-web module available. If you want better web container support, please= add the log4j-web JAR to your web archive or server lib directory. DEBUG Missing dependencies for Yaml support INFO Log4j appears to be running in a Servlet environment, but there's no l= og4j-web module available. If you want better web container support, please= add the log4j-web JAR to your web archive or server lib directory. DEBUG Missing dependencies for Json support INFO Log4j appears to be running in a Servlet environment, but there's no l= og4j-web module available. If you want better web container support, please= add the log4j-web JAR to your web archive or server lib directory. DEBUG Using configurationFactory org.apache.logging.log4j.core.config.Confi= gurationFactory$Factory@122b3406 TRACE Trying to find [log4j2-test-578826301.xml] using context class loader= =20 ... TRACE Trying to find [log4j2.xml] using ClassLoader.getSystemResource(). ERROR No log4j2 configuration file found. Using default configuration: logg= ing only errors to the console. ... DEBUG LoggerContext[name=3D-578826301, org.apache.logging.log4j.core.Logger= Context@86474db1] started OK. {panel} So calling {{Configurator.initiallze()}} will be handled in different ways = depending on the type of application. And the *overwhelming INFO messges are misleading as there is no {{web.xml}= } in a pure EJB app*. I'm interested in a single solution for both types of apps. Another fact why I'm confident that the implementation of the else case in = {{ConfigurationFactory$Factory.getConfiguration()}} is missing and needed f= or a single solution is the following:=20 Setting your own {{ConfigurationFactory}} via {{ConfigurationFactory.setCo= nfigurationFactory(new MyConfigurationFactory());}} *programmatically* work= s fine merely by overriding the method {{public Configuration getConfigurat= ion(String name, URI configLocation, ClassLoader loader)}} which makes a lo= okup to the URL resource and provides the {{Configuration}} in a dynamical = way. *Why and where should I call {{Configurator.initiallze()}} in this cas= e?* When I'm using the *declarative approach* instead with the {{log4j2.compone= nt.properties}} file my overridden method {{getConfiguration}} will not be = called any more - because of the *missing else case in {{ConfigurationFacto= ry$Factory.getConfiguration()}}*. was (Author: gecko21): We are using Web applications (w/ web.xml) and pure EJB applications (w/o w= eb.xml). Why should I use the log4j-web module in an EJB app? And what does it mean 'each EJBs initialization call Configurator.initiallz= e() ...have their own configuration'? We need one configuration per app not per EJB. Besides, when and where to call Configurator.initiallze() is not mentioned = in the official Log4j2 documentation - stackoverflow.com mentions it at lea= st. And how will you 'set log4j.configurationFile to the URL you want to use'?= =20 Remember the URL must be set dynamically per app meaning via a lookup to a = URL resource of WAS8 - neither hard coded in your app nor via a system prop= erty which has server scope. In a Web app I defined MyConfiguartionFactory and in the constructor I'm ca= lling Configurator.initiallze() where the last argument is the URI to the v= alue of my URL resource defined in WebSphere. I used MyConfiguartionFactory= by setting the property log4j.configurationFactory in log4j2.component.pro= perties - this works fine. Then I tried to use the same (MyConfiguartionFactory in log4j2.component.pr= operties) in a pure EJB app (Singleton Startup Bean and several other EJB S= LSBs). There this solution fails. The log trace shows that first my configu= ration with my URL resource started successfully but immediately after that= it's stopped automatically and replaced by a second start of a default con= figuration which fails that way that it cannot find any log4j2.xml saying o= nly ERRORs and FATALs are logged to console. ---------------------------------------------------------------------------= --------------------------------------------------- DEBUG Starting configuration XmlConfiguration[location=3DD:\logs\log4j2.xml= ] ... INFO Log4j appears to be running in a Servlet environment, but there's no l= og4j-web module available. If you want better web container support, please= add the log4j-web JAR to your web archive or server lib directory. ... DEBUG Started configuration XmlConfiguration[location=3DD:\logs\log4j2.xml]= OK. TRACE Stopping org.apache.logging.log4j.core.config.DefaultConfiguration@cd= 868062... TRACE AbstractConfiguration stopped 0 AsyncLoggerConfigs. TRACE AbstractConfiguration stopped 0 AsyncAppenders. TRACE AbstractConfiguration stopped 1 Appenders. TRACE AbstractConfiguration stopped 0 Loggers. DEBUG Stopped org.apache.logging.log4j.core.config.DefaultConfiguration@cd8= 68062 OK ... DEBUG Reconfiguration complete for context[name=3D-578826301] at file:D:/lo= gs/log4j2.xml (org.apache.logging.log4j.core.LoggerContext@86474db1) with o= ptional ClassLoader: null DEBUG PluginManager 'ConfigurationFactory' found 3 plugins INFO Log4j appears to be running in a Servlet environment, but there's no l= og4j-web module available. If you want better web container support, please= add the log4j-web JAR to your web archive or server lib directory. DEBUG Missing dependencies for Yaml support INFO Log4j appears to be running in a Servlet environment, but there's no l= og4j-web module available. If you want better web container support, please= add the log4j-web JAR to your web archive or server lib directory. DEBUG Missing dependencies for Json support INFO Log4j appears to be running in a Servlet environment, but there's no l= og4j-web module available. If you want better web container support, please= add the log4j-web JAR to your web archive or server lib directory. DEBUG Using configurationFactory org.apache.logging.log4j.core.config.Confi= gurationFactory$Factory@122b3406 TRACE Trying to find [log4j2-test-578826301.xml] using context class loader= =20 ... TRACE Trying to find [log4j2.xml] using ClassLoader.getSystemResource(). ERROR No log4j2 configuration file found. Using default configuration: logg= ing only errors to the console. ... DEBUG LoggerContext[name=3D-578826301, org.apache.logging.log4j.core.Logger= Context@86474db1] started OK. ---------------------------------------------------------------------------= --------------------------------------------------- So calling Configurator.initiallze() will be handled in different ways depe= nding on the type of application. And the overwhelming INFO messges are misleading as there is no web.xml in = a pure EJB app. I'm interested in a single solution for both types of apps. Another fact why I'm confident that the implementation of the else case in = ConfigurationFactory$Factory.getConfiguration() is missing and needed for a= single solution is the following:=20 Setting your own ConfigurationFactory via 'ConfigurationFactory.setConfigu= rationFactory(new MyConfigurationFactory());' programmatically works fine m= erely by overriding the method 'public Configuration getConfiguration(Strin= g name, URI configLocation, ClassLoader loader)' which makes a lookup to th= e URL resource and provides the Configuration in a dynamical way. Why and w= here should I call Configurator.initiallze() in this case? When I'm using the declarative approach instead with the log4j2.component.p= roperties file my overridden method getConfiguration will not be called any= more - because of the missing else case in ConfigurationFactory$Factory.ge= tConfiguration(). > WAS8: externalize log4j2.xml via URL resource > --------------------------------------------- > > Key: LOG4J2-1045 > URL: https://issues.apache.org/jira/browse/LOG4J2-1045 > Project: Log4j 2 > Issue Type: Bug > Components: Configurators > Affects Versions: 2.3 > Environment: WebSphere 8.0; Win7 x64 > Reporter: G=C3=BCnter Albrecht > Labels: patch > > We're working with WebSphere 8.0 and our operations team has demanded to = externalize the {{log4j2.xml}} file per application. > So I defined a URL resource on WAS8 containing the path to the {{log4j2.x= ml}} somewhere on the filesystem. > At first glance the solution seems very simple: > I defined the property {{log4j.configurationFactory}} in the {{log4j2.com= ponent.properties}} file {{log4j.configurationFactory=3Dde.company.MyConfig= urationFactory}} available via classpath of the application. > In this class I specialized the method {{public Configuration getConfigur= ation(String name, URI configLocation, ClassLoader loader)}}. There I make = a lookup to the URL resource. > But it does'nt function as of a missing implementation in the class {{Con= figurationFactory$Factory}} and the method {{public Configuration getConfig= uration(final String name, final URI configLocation)}}. When one enters the= method the variable {{configLocation}} is {{null}}. Then the property {{lo= g4j.configurationFile}} is checked which is intentionally not set in the {{= log4j2.component.properties}} file as it must be dynamical - via a URL reso= urce. > Hence also the variable {{config}} is {{null}}. *Unfortunately merely {{c= onfig !=3D null}} is handled and no else case is implemented.* > So my improvement is to implement an else case which is identical to the = else case of {{if (configLocation =3D=3D null)}}. > With this solution I do not have to implement cumbersome versions for Web= - and EJB-applications.=20 -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org For additional commands, e-mail: log4j-dev-help@logging.apache.org