[
https://issues.apache.org/jira/browse/LOG4J2-1045?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14578624#comment-14578624
]
Günter Albrecht edited comment on LOG4J2-1045 at 6/9/15 9:44 AM:
-----------------------------------------------------------------
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.initiallze()
...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 least.
And how will you 'set log4j.configurationFile to the URL you want to use'?
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 property
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 URI to the
value of my URL resource defined in WebSphere. I used MyConfiguartionFactory by
setting the property log4j.configurationFactory in log4j2.component.properties
- this works fine.
Then I tried to use the same (MyConfiguartionFactory in
log4j2.component.properties) in a pure EJB app (Singleton Startup Bean and
several other EJB SLSBs). There this solution fails. The log trace shows that
first my configuration with my URL resource started successfully but
immediately after that it's stopped automatically and replaced by a second
start of a default configuration which fails that way that it cannot find any
log4j2.xml saying only ERRORs and FATALs are logged to console.
------------------------------------------------------------------------------------------------------------------------------
DEBUG Starting configuration XmlConfiguration[location=D:\logs\log4j2.xml]
...
INFO Log4j appears to be running in a Servlet environment, but there's no
log4j-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=D:\logs\log4j2.xml] OK.
TRACE Stopping
org.apache.logging.log4j.core.config.DefaultConfiguration@cd868062...
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@cd868062 OK
...
DEBUG Reconfiguration complete for context[name=-578826301] at
file:D:/logs/log4j2.xml (org.apache.logging.log4j.core.LoggerContext@86474db1)
with optional ClassLoader: null
DEBUG PluginManager 'ConfigurationFactory' found 3 plugins
INFO Log4j appears to be running in a Servlet environment, but there's no
log4j-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
log4j-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
log4j-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.ConfigurationFactory$Factory@122b3406
TRACE Trying to find [log4j2-test-578826301.xml] using context class loader
...
TRACE Trying to find [log4j2.xml] using ClassLoader.getSystemResource().
ERROR No log4j2 configuration file found. Using default configuration: logging
only errors to the console.
...
DEBUG LoggerContext[name=-578826301,
org.apache.logging.log4j.core.LoggerContext@86474db1] started OK.
------------------------------------------------------------------------------------------------------------------------------
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 for a
single solution is the following:
Setting your own ConfigurationFactory via
'ConfigurationFactory.setConfigurationFactory(new MyConfigurationFactory());'
programmatically works fine merely by overriding the method 'public
Configuration getConfiguration(String name, URI configLocation, ClassLoader
loader)' which makes a lookup to the URL resource and provides the
Configuration in a dynamical way. Why and where should I call
Configurator.initiallze() in this case?
When I'm using the declarative approach instead with the
log4j2.component.properties file my overridden method getConfiguration will not
be called any more - because of the missing else case in
ConfigurationFactory$Factory.getConfiguration().
was (Author: gecko21):
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.initiallze()
...have their own configuration'?
We need one configuartion 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 least.
And how will you 'set log4j.configurationFile to the URL you want to use'?
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 property
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 URI to the
value of my URL resource defined in WebSphere. I used MyConfiguartionFactory by
setting the property log4j.configurationFactory in log4j2.component.properties
- this works fine.
Then I tried to use the same (MyConfiguartionFactory in
log4j2.component.properties) in a pure EJB app (Singleton Startup Bean and
several other EJB SLSBs). There this solution fails. The log trace shows that
first my configuration with my URL resource started successfully but
immediately after that it's stopped automatically and replaced by a second
start of a default configuration which fails that way that it cannot find any
log4j2.xml saying only ERRORs and FATALs are logged to console.
------------------------------------------------------------------------------------------------------------------------------
DEBUG Starting configuration XmlConfiguration[location=D:\logs\log4j2.xml]
...
INFO Log4j appears to be running in a Servlet environment, but there's no
log4j-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=D:\logs\log4j2.xml] OK.
TRACE Stopping
org.apache.logging.log4j.core.config.DefaultConfiguration@cd868062...
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@cd868062 OK
...
DEBUG Reconfiguration complete for context[name=-578826301] at
file:D:/logs/log4j2.xml (org.apache.logging.log4j.core.LoggerContext@86474db1)
with optional ClassLoader: null
DEBUG PluginManager 'ConfigurationFactory' found 3 plugins
INFO Log4j appears to be running in a Servlet environment, but there's no
log4j-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
log4j-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
log4j-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.ConfigurationFactory$Factory@122b3406
TRACE Trying to find [log4j2-test-578826301.xml] using context class loader
...
TRACE Trying to find [log4j2.xml] using ClassLoader.getSystemResource().
ERROR No log4j2 configuration file found. Using default configuration: logging
only errors to the console.
...
DEBUG LoggerContext[name=-578826301,
org.apache.logging.log4j.core.LoggerContext@86474db1] started OK.
------------------------------------------------------------------------------------------------------------------------------
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 for a
single solution is the following:
Setting your own ConfigurationFactory via
'ConfigurationFactory.setConfigurationFactory(new MyConfigurationFactory());'
programmatically works fine merely by overriding the method 'public
Configuration getConfiguration(String name, URI configLocation, ClassLoader
loader)' which makes a lookup to the URL resource and provides the
configLocation in a dynamical way. Why and where should I call
Configurator.initiallze() in this case?
When I'm using the declarative approach instead with the
log4j2.component.properties file my overridden method getConfiguration will not
be called any more - because of the missing else case in
ConfigurationFactory$Factory.getConfiguration().
> WAS8: externalize log4j2.xml via URL resource
> ---------------------------------------------
>
> Key: LOG4J2-1045
> URL: https://issues.apache.org/jira/browse/LOG4J2-1045
> Project: Log4j 2
> Issue Type: Improvement
> Components: Configurators
> Affects Versions: 2.3
> Environment: WebSphere 8.0; Win7 x64
> Reporter: Günter 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.xml
> somewhere on the filesystem.
> At first glance the solution seems very simple:
> I defined the property log4j.configurationFactory in the
> log4j2.component.properties file
> (log4j.configurationFactory=de.company.MyConfigurationFactory) available via
> classpath of the application.
> In this class I specialized the method 'public Configuration
> getConfiguration(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
> ConfigurationFactory$Factory and the method 'public Configuration
> getConfiguration(final String name, final URI configLocation)'. When one
> enters the method the variable configLocation is null. Then the property
> 'log4j.configurationFile' is checked which is intentionally not set in the
> log4j2.component.properties file as it must be dynamical - via a URL resource.
> Hence also the variable config is null. Unfortunately merely 'config != 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 == null) {'.
> With this solution I do not have to implement cumbersome versions for Web-
> and EJB-applications.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]