logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul <pgbak...@gmail.com>
Subject Re: Application Server integration in Tomcat
Date Sun, 24 Feb 2019 09:46:32 GMT
Ghee, that was it, at least for getting the internal Tomcat logging to 
go through Log4j.

It didn't solve my static field thing, but that one I also figured out. 
Not 100% sure my reasoning is correct, but I think it's due to how 
classloading works in Servlets and thus in Tomcat (by default): the 
classloaders for webapps do NOT delegate classloading requests to the 
parent classloader (by default), thus the same class can be loaded 
multiple times: in my case by the bootstrap/system classloader and by 
the webapp classloader. And I guess depending on how my webapp 
application code tries to access the static field on the appender (don't 
have insight to this code, it's a 3rd party framework), it doesn't find 
the one where the appender constructor was called on, as my webapp code 
gets the class loaded by the webapp classloader, whereas log4j seems to 
load all plugins when log4j gets initialized the first time, which is 
for Tomcat internal logging, which happens using the bootstrap/system 
classloaders.

I tried adding the custom appenders to the WEB-INF/lib of my webapp 
(while all other log4j jars live in the tomcat/lib), but this doesn't 
work: the loading of log4j.properties in WEB-INF bombs out, because 
log4j cannot find the custom appender.

Once I added <Loader delegate="true"/> to the Context, things started to 
work. As I'm only deploying this one webapp, this works fine for me (or 
so it seems).

If the above makes no sense or there are better ways to get things 
going, I'd love to hear it

Tnx for the help so far!

Paul

On 23/02/2019 07:40, Ralph Goers wrote:
> I just noticed that you said you have setenv.sh set to
> CLASSPATH=“$CATALINA_HOME/lib/*”
>
> That will find the jars but it won’t find your configuration file. You need to specify
> CLASSPATH=“$CATALINA_HOME/lib/*:${CATALINA_HOME}/lib”
>
> Note that lib is specified twice, once with “/*” after it and once with nothing.
>
> Ralph
>
>> On Feb 19, 2019, at 9:03 AM, Paul <pgbakker@gmail.com> wrote:
>>
>> Hi,
>>
>> Am trying to get Tomcat to log internal stuff through Log4j2, but failing, no matter
how I try.
>>
>> I've followed the instruction at https://logging.apache.org/log4j/2.x/log4j-appserver/index.html
to no avail.
>>
>> I have a hard time understanding it, but maybe the problem is that the Log4j2 code
is executed in a different classLoader than the tomcat code: I've enabled classloading debug
output (-Xlog:class+load*=debug) and the status logger (-Dlog4j2.debug) and I see that all
Tomcat code is executed by one classloader:
>>
>> loader: [loader data: 0x000055f64b4557e0 of 'bootstrap']
>>
>> whereas the Log4j2 code seems executed by a different classloader:
>>
>> loader: [loader data: 0x00005559e1327de0 for instance a 'jdk/internal/loader/ClassLoaders$AppClassLoader'{0x00000000e10c9c20}]
>>
>> I have this in setenv.sh and setenv.sh is working properly otherwise:
>> CLASSPATH="$CATALINA_HOME/lib/*"
>>
>> The $CATALINA_HOME/lib/ contains my log4j2-tomcat.properties and the log4j-api and
log4j-core jars (alongside slf4j-api.jar and log4j-slf4j-impl.jar).  (all version 2.11.x)
>>
>> I've also tried with the log4j-webon the classPath, didn't make a difference. Tried
the -Dlog4j.ignoreTCL=true options, no luck.
>>
>> In the end, my main purpose it to log everything that happens in the JVM through
log4j2 to the console. I've also tried with log4j-jul-2.11.1.jar, but couldn't get that going
either: one of the challenges I have is that I have a custom appender plugin that needs to
be loaded within the same classLoader hierarchy as where my (single) webapp is running. In
the end, I'll be running only 1 webapp, deployed as a WAR in TOmcat and the whole thing is
dockerized, so neither Tomcat or the WAR are ever restarted/redeployed: if something needs
to change, we'll deploy a new container image
>>
>> The output to the console of Tomcat is this:
>> Using CATALINA_BASE:   /usr/local/tomcat
>> Using CATALINA_HOME:   /usr/local/tomcat
>> Using CATALINA_TMPDIR: /usr/local/tomcat/temp
>> Using JRE_HOME: /usr/lib/jvm/zulu11.2.3-jdk11.0.1-linux_musl_x64
>> Using CLASSPATH: /usr/local/tomcat/lib/*:/usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
>> NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED
--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
>> NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED
--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
>> DEBUG StatusLogger Using ShutdownCallbackRegistry class org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry
>> INFO StatusLogger 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.
>> INFO StatusLogger 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 StatusLogger Took 0.143572 seconds to load 208 plugins from jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
>> DEBUG StatusLogger PluginManager 'Converter' found 44 plugins
>> DEBUG StatusLogger Starting OutputStreamManager SYSTEM_OUT.false.false-1
>> DEBUG StatusLogger Starting LoggerContext[name=799f7e29, org.apache.logging.log4j.core.LoggerContext@ae13544]...
>> DEBUG StatusLogger Reconfiguration started for context[name=799f7e29] at URI null
(org.apache.logging.log4j.core.LoggerContext@ae13544) with optional ClassLoader: null
>> INFO StatusLogger 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 StatusLogger PluginManager 'ConfigurationFactory' found 4 plugins
>> INFO StatusLogger 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.
>> INFO StatusLogger 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 StatusLogger Missing dependencies for Yaml support, ConfigurationFactory org.apache.logging.log4j.core.config.yaml.YamlConfigurationFactory
is inactive
>> INFO StatusLogger 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 StatusLogger Missing dependencies for Json support, ConfigurationFactory org.apache.logging.log4j.core.config.json.JsonConfigurationFactory
is inactive
>> INFO StatusLogger 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 StatusLogger Using configurationFactory org.apache.logging.log4j.core.config.ConfigurationFactory$Factory@4e50c791
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.properties] using context
class loader jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.properties] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.properties] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.properties] using ClassLoader.getSystemResource().
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.yml] using context class loader
jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.yml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.yml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.yml] using ClassLoader.getSystemResource().
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.yaml] using context class
loader jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.yaml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.yaml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.yaml] using ClassLoader.getSystemResource().
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.json] using context class
loader jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.json] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.json] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.json] using ClassLoader.getSystemResource().
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.jsn] using context class loader
jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.jsn] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.jsn] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.jsn] using ClassLoader.getSystemResource().
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.xml] using context class loader
jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.xml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.xml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test799f7e29.xml] using ClassLoader.getSystemResource().
>> TRACE StatusLogger Trying to find [log4j2-test.properties] using context class loader
jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2-test.properties] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test.properties] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test.properties] using ClassLoader.getSystemResource().
>> TRACE StatusLogger Trying to find [log4j2-test.yml] using context class loader jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2-test.yml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test.yml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test.yml] using ClassLoader.getSystemResource().
>> TRACE StatusLogger Trying to find [log4j2-test.yaml] using context class loader jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2-test.yaml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test.yaml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test.yaml] using ClassLoader.getSystemResource().
>> TRACE StatusLogger Trying to find [log4j2-test.json] using context class loader jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2-test.json] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test.json] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test.json] using ClassLoader.getSystemResource().
>> TRACE StatusLogger Trying to find [log4j2-test.jsn] using context class loader jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2-test.jsn] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test.jsn] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test.jsn] using ClassLoader.getSystemResource().
>> TRACE StatusLogger Trying to find [log4j2-test.xml] using context class loader jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2-test.xml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test.xml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2-test.xml] using ClassLoader.getSystemResource().
>> TRACE StatusLogger Trying to find [log4j2799f7e29.properties] using context class
loader jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2799f7e29.properties] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2799f7e29.properties] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2799f7e29.properties] using ClassLoader.getSystemResource().
>> TRACE StatusLogger Trying to find [log4j2799f7e29.yml] using context class loader
jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2799f7e29.yml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2799f7e29.yml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2799f7e29.yml] using ClassLoader.getSystemResource().
>> TRACE StatusLogger Trying to find [log4j2799f7e29.yaml] using context class loader
jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2799f7e29.yaml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2799f7e29.yaml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2799f7e29.yaml] using ClassLoader.getSystemResource().
>> TRACE StatusLogger Trying to find [log4j2799f7e29.json] using context class loader
jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2799f7e29.json] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2799f7e29.json] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2799f7e29.json] using ClassLoader.getSystemResource().
>> TRACE StatusLogger Trying to find [log4j2799f7e29.jsn] using context class loader
jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2799f7e29.jsn] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2799f7e29.jsn] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2799f7e29.jsn] using ClassLoader.getSystemResource().
>> TRACE StatusLogger Trying to find [log4j2799f7e29.xml] using context class loader
jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2799f7e29.xml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2799f7e29.xml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2799f7e29.xml] using ClassLoader.getSystemResource().
>> TRACE StatusLogger Trying to find [log4j2.properties] using context class loader
jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2.properties] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2.properties] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2.properties] using ClassLoader.getSystemResource().
>> TRACE StatusLogger Trying to find [log4j2.yml] using context class loader jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2.yml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2.yml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2.yml] using ClassLoader.getSystemResource().
>> TRACE StatusLogger Trying to find [log4j2.yaml] using context class loader jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2.yaml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2.yaml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2.yaml] using ClassLoader.getSystemResource().
>> TRACE StatusLogger Trying to find [log4j2.json] using context class loader jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2.json] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2.json] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2.json] using ClassLoader.getSystemResource().
>> TRACE StatusLogger Trying to find [log4j2.jsn] using context class loader jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2.jsn] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2.jsn] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2.jsn] using ClassLoader.getSystemResource().
>> TRACE StatusLogger Trying to find [log4j2.xml] using context class loader jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29.
>> TRACE StatusLogger Trying to find [log4j2.xml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2.xml] using jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
class loader.
>> TRACE StatusLogger Trying to find [log4j2.xml] using ClassLoader.getSystemResource().
>> ERROR StatusLogger No Log4j 2 configuration file found. Using default configuration
(logging only errors to the console), or user programmatically provided configurations. Set
system property 'log4j2.debug' to show Log4j 2 internal initialization logging. See https://logging.apache.org/log4j/2.x/manual/configuration.html
for instructions on how to configure Log4j 2
>> INFO StatusLogger 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.
>>
>>
>> ---
>> This email has been checked for viruses by AVG.
>> https://www.avg.com
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>

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


Mime
View raw message