Re: Fwd: Advice please for Tomcat 8.5.53-dev with log4j2

2020-03-19 Thread Brian Burch

On 18/3/20 5:54 pm, Luis Rodríguez Fernández wrote:

Grande Brian, congrats!

Sorry, I've just read your message, a bit late to the party: time ago I had
cooked a tomcat9 container + log4j2 with a sample spring-boot app deployed.
You can have a look here [1]


Thanks very much, Luis. Although just too late to help me, I was pleased 
to discover it confirmed Mark's advice and my own experience.


I guess I missed it from my own searches because I was focussed on the 
major logging transition between tomcat 7 and the early tomcat 8 
version, but your post was prominently identified with tomcat 9.


I have a busy weekend with non-self-isolating(!) family and friends, but 
I have a strong intention to draft an update to the tc8 wiki next week 
to match the current facts. Probably it will prove trivial for someone 
to port my change to the tc9 pages.


Thanks again for your thoughts,

Brian


Cheers,

Luis

[1]
https://db-blog.web.cern.ch/blog/luis-rodriguez-fernandez/2019-03-keeping-your-logs-clean-apache-tomcat-9-log4j2-and-spring-boot

El mié., 18 mar. 2020 a las 8:44, Brian Burch ()
escribió:


On 18/3/20 5:18 pm, Brian Burch wrote:




Could resist tinkering a bit more, but I'll be in trouble because I'm
late for dinner!!

Success! I have just created the catalina.log file formatted according
to my own log4j2.xml.

Yes, it was my stupid mistake, but I'll write tomorrow about what it did
to make it work.

Thanks for listening and advising. It really helped a lot and I wouldn't
have cracked it on my own.

Brian

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org







-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Fwd: Advice please for Tomcat 8.5.53-dev with log4j2

2020-03-18 Thread Luis Rodríguez Fernández
Grande Brian, congrats!

Sorry, I've just read your message, a bit late to the party: time ago I had
cooked a tomcat9 container + log4j2 with a sample spring-boot app deployed.
You can have a look here [1]

Cheers,

Luis

[1]
https://db-blog.web.cern.ch/blog/luis-rodriguez-fernandez/2019-03-keeping-your-logs-clean-apache-tomcat-9-log4j2-and-spring-boot

El mié., 18 mar. 2020 a las 8:44, Brian Burch ()
escribió:

> On 18/3/20 5:18 pm, Brian Burch wrote:
> > 
>
> Could resist tinkering a bit more, but I'll be in trouble because I'm
> late for dinner!!
>
> Success! I have just created the catalina.log file formatted according
> to my own log4j2.xml.
>
> Yes, it was my stupid mistake, but I'll write tomorrow about what it did
> to make it work.
>
> Thanks for listening and advising. It really helped a lot and I wouldn't
> have cracked it on my own.
>
> Brian
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>

-- 

"Ever tried. Ever failed. No matter. Try Again. Fail again. Fail better."

- Samuel Beckett


Re: Fwd: Advice please for Tomcat 8.5.53-dev with log4j2

2020-03-18 Thread Brian Burch

On 18/3/20 5:18 pm, Brian Burch wrote:




Could resist tinkering a bit more, but I'll be in trouble because I'm 
late for dinner!!


Success! I have just created the catalina.log file formatted according 
to my own log4j2.xml.


Yes, it was my stupid mistake, but I'll write tomorrow about what it did 
to make it work.


Thanks for listening and advising. It really helped a lot and I wouldn't 
have cracked it on my own.


Brian

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Fwd: Advice please for Tomcat 8.5.53-dev with log4j2

2020-03-18 Thread Brian Burch

On 18/3/20 2:57 pm, Brian Burch wrote:




I have done quite a lot of experiments, but I will stick to the case 
which appears to have produced the most encouraging(!) results.


I stumbled across 
https://logging.apache.org/log4j/2.x/log4j-appserver/index.html.


This short page has significant overlap with your suggestions, but there 
are differences too. I'll compare both before I say much more.


Your setenv puts log4j-api-2.13.1.jar on the classpath, but this file 
does not exist in my log4j2 binary download.


Following their advice, I first tried replacing it with 
log4j-appserver-2.13.1.jar, but startup failed with ClassNotFoundException.


Then I added (not replaced) log4j-1.2-api-2.13.1.jar, which seemed to be 
a good guess. That failed as follows:


Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: org.apache.juli.logging.LogConfigurationException: 
java.lang.reflect.InvocationTargetException
at 
org.apache.juli.logging.LogFactory.getInstance(LogFactory.java:136)
at 
org.apache.juli.logging.LogFactory.getInstance(LogFactory.java:153)

at org.apache.juli.logging.LogFactory.getLog(LogFactory.java:208)
at 
org.apache.catalina.startup.Bootstrap.(Bootstrap.java:51)

Caused by: java.lang.reflect.InvocationTargetException
at 
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at 
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at 
org.apache.juli.logging.LogFactory.getInstance(LogFactory.java:134)

... 3 more
Caused by: java.lang.NoClassDefFoundError: 
org/apache/logging/log4j/LogManager

at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at 
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)

at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at 
org.apache.logging.log4j.appserver.tomcat.TomcatLogger.(TomcatLogger.java:67)

... 8 more

However, I suspected my "current best effort" had disabled the internal 
tomcat logging (juli) but failed to enable log4j2. The message I quoted 
from catalina.out looked suspiciously like it had been handled by the 
jvm Logger, which is consistent with your suggestion

> I tried building log4j2 from source and gave up. It is a bit of a
nuisance that my development system uses both OpenJDK 8 and 11 because I 
keep forgetting which is required by my different projects. The log4j2 
toolchains requirement for java 9 was just too much to contemplate!


Clearly, adding log4j-1.2-api-2.13.1.jar did something significant, but 
I guess the jar is incompatible in some manner?


I recall the log4j2 pom.xml has a java.target of 1.7, as well as its 
toolchain requirement for java 9. I'm doing my very best to build and 
run tomcat under java 8. Is this relevant, or just a red herring?


I downloaded the apache-log4j-2.13.1 binaries, so I will deploy those 
jars in my tests.


I needed to make some minor tweaks to your setenv.bat before I had a 
syntax-free setenv.sh. Of course, I also replaced your ${CATALINA_BASE} 
with ${CATALINA_HOME} because that's where I'm currently putting the 
logging jars.


That bootstrap directory also has a copy of tomcat-juli from my java 8 
build from 5.8.53-dev source:-


-rw-r--r-- 1 tomcat8 tomcat8   51224 Mar  9 17:24 tomcat-juli.jar

I also noted from the web advice above that log4j2 looks for it's 
configuration file under the name log4j2-tomcat.xml, not log4j2.xml. I'm 
not keen on the advice to deploy the jars to new tomcat directories 
called catalina.home/log4j2/lib and ./log4j2/conf, so I favour your 
suggestion of using catalina.home/bin for my first tests.


Oh yes...

It didn't make any difference whether I called my configuration file 
conf/log4j2.xml or conf/log4j2-tomcat.xml.


I don't think it should matter that the default conf/logging.properties 
does not exist... wdyt?


I really appreciate your thoughtful advice. It would be useful for me to 
pare the advice down to its essentials and then update the tomcat 8 wiki 
advice.


So, to summarise, I've eliminated a lot of possible solutions and 
changed the failure 

Fwd: Advice please for Tomcat 8.5.53-dev with log4j2

2020-03-17 Thread Brian Burch

Thanks very much for your speedy and helpful reply, Mark.

Stupidly, I had forgotten to re-subscribe to the mailing list, so I 
found your reply in the archive and cannot reply to it in-line!


not really!

I stumbled across 
https://logging.apache.org/log4j/2.x/log4j-appserver/index.html.


This short page has significant overlap with your suggestions, but there 
are differences too. I'll compare both before I say much more.


However, I suspected my "current best effort" had disabled the internal 
tomcat logging (juli) but failed to enable log4j2. The message I quoted 
from catalina.out looked suspiciously like it had been handled by the 
jvm Logger, which is consistent with your suggestion.


I tried building log4j2 from source and gave up. It is a bit of a 
nuisance that my development system uses both OpenJDK 8 and 11 because I 
keep forgetting which is required by my different projects. The log4j2 
toolchains requirement for java 9 was just too much to contemplate!


I downloaded the apache-log4j-2.13.1 binaries, so I will deploy those 
jars in my tests.


I also noted from the web advice above that log4j2 looks for it's 
configuration file under the name log4j2-tomcat.xml, not log4j2.xml. I'm 
not keen on the advice to deploy the jars to new tomcat directories 
called catalina.home/log4j2/lib and ./log4j2/conf, so I favour your 
suggestion of using catalina.home/bin for my first tests.


I really appreciate your thoughtful advice. It would be useful for me to 
pare the advice down to its essentials and then update the tomcat 8 wiki 
advice.


Brian


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Advice please for Tomcat 8.5.53-dev with log4j2

2020-03-17 Thread Mark Thomas
On 17/03/2020 06:05, Brian Burch wrote:
> I have a very frozen and stable tomcat 7.0.68 system with a lot of apps.
> It was build from source and uses the extras tomcat-juli.jar with
> log4j-1.2.17.jar.
> 
> Both tomcat and my webapps log successfully via log4j (except, of
> course, the access log valve).
> 
> The time has come to bring the whole system up to date, but I don't want
> to jump too far in a single leap, so I am trying to port the production
> environment to a new server image. (The old system is ubuntu 16.04.6 LTS
> 32-bit. The new system is 18.04.3 LTS 64-bit).



> I would be very grateful for any advice to make my tomcat8 use log4j2. I
> hope this advice will permit me to recommend some improvements to the
> relevant pages of the tomcat wiki...

I haven't test this extensively so there may be some edge case that need
fixing.

Some background for those who may be less familiar with the topic.

JULI, as provided by Tomcat, is a packaged renamed version of Apache
Commons Logging hard-coded to output to java.util.logging.

The old log4j extras package (still present in Tomcat 7) was a packaged
renamed version of Apache Commons Logging hard-coded to output to log4j v1.

Essentially, there were two logging implementations and you picked the
one you wanted.

With log4j v1 reaching end-of-life, Tomcat 8.5.x onwards has the option
of outputting to log4j v2 but the way it is configured is very different.

log4j v2 provides an adaptor that lets it "intercept" log messages sent
to java.util.logging. The idea is that this adapter is used with Tomcat
8.5.x onwards.

The configuration steps are (using v2.13.1):

0. Leave the Tomcat logging configuration as is.

1. Add the required log4j JARs. They are:
   - log4j-jul-2.13.1.jar
   - log4j-api-2.13.1.jar
   - log4j-core-2.13.1.jar

Where you put them doesn't really matter. For consistency with Tomcat
I'd place them in the bin directory.

2. Add the required configuration file. For consistency with Tomcat I'd
call it log4j2.xml and place it in the conf directory. The file I used was:



  

  

  
  

  

  


This is essentially the default config but with the logging level
changed to info so you actually see something.

3. You then need to configure:
   - the java.util.logging logging manager so log4j v2 intercepts the
 log messages
   - the configuration file so the right messages are logged
   - the classpath so the log4j v2 JARs are found.

You can do all of this in setenv.[sh|bat]. The file I used was:

!#/bin/sh
JAVA_OPTS="-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager
-Dlog4j.configurationFile=$CATALINA_BASE/conf/log4j2.xml"
CLASSPATH=$CATALINA_BASE/bin/log4j-jul-2.13.1.jar:$CATALINA_BASE/bin/log4j-core-2.13.1.jar:$CATALINA_BASE/bin/log4j-api-2.13.1.jar

Excuse the poor formatting with line wrapping and adjust appropriately
if you are on Windows.

I used CATALINA_BASE above but it works equally well with CATALINA_HOME.
If you have split HOME and BASE you can configure this on either.

All of this was with Tomcat 10 but it should be the same with 9.0.x and
8.5.x.

A patch or PR to add the above (once you have confirmed it is complete)
to https://github.com/apache/tomcat/blob/master/webapps/docs/logging.xml
would be very helpful.

> Thanks in anticipation,
> 
> Brian
> 
> (back on the list after nearly 4 years away!)

Welcome back.

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Advice please for Tomcat 8.5.53-dev with log4j2

2020-03-17 Thread Brian Burch
I have a very frozen and stable tomcat 7.0.68 system with a lot of apps. 
It was build from source and uses the extras tomcat-juli.jar with 
log4j-1.2.17.jar.


Both tomcat and my webapps log successfully via log4j (except, of 
course, the access log valve).


The time has come to bring the whole system up to date, but I don't want 
to jump too far in a single leap, so I am trying to port the production 
environment to a new server image. (The old system is ubuntu 16.04.6 LTS 
32-bit. The new system is 18.04.3 LTS 64-bit).


I have read (very carefully) the tomcat8 logging.html, 
extras.html#Full_commons-logging_implementation and 
class-loader-howto.html. I am aware of 
https://bz.apache.org/bugzilla/show_bug.cgi?id=58588. They have confused 
me, even though I've read them a lot in the past!


I have built tomcat 8.5.53-dev under OpenJDK 1.8.0_232 (64 bit), and 
also the extras. tomcat also executes under jdk8.


Extras no longer builds the full logging jar, so I am apparently forced 
to use the tomcat-juli.jar from the main build. log4j has moved from 
version 1 to 2, with quite a few changes, so I decided to implement 
log4j2 right from the start.


To simplify my conversion effort, I decided to get tomcat itself logging 
via laog4j2 before I converted any of the webapps. That has been a 
frustrating and unsuccessful task so far!


I can confirm the experience of others - unless tomcat-juli.jar is in 
the same directory as bootstrap.jar (catalina.home/bin), startup fails 
with ClassNotFoundException.


I do NOT have a logging.properties file in conf.

catalina.base/lib has my log4j2.xml, along with log4j-api.jar, 
log4j-core.jar and log4j-jul.jar. I have tried them in a lot of places, 
including catalina.home/bin, catalina.base/system, common and server, 
but nothing seems to improve.


/var/log/tc8/catalina.out reports (apologies for nasty line breaks):

Mar 17, 2020 8:45:34 AM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: 
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager


But there are no initialisation messages from log4j2.

The log4j2 Root Logger has AppenderRef to a RollingFileAppender with 
fileName="${logdir}/catalina.log" (where logdir resolves to 
/var/log/tomcat/).


I am not convinced catalina.out is being handled by log4j2 at all!

I would be very grateful for any advice to make my tomcat8 use log4j2. I 
hope this advice will permit me to recommend some improvements to the 
relevant pages of the tomcat wiki...


Thanks in anticipation,

Brian

(back on the list after nearly 4 years away!)

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org