Hi Chris, > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA256 > > Thomas, > > On 2/21/19 07:20, Thomas Rohde wrote: > > Hi Chris, > > > > -----Ursprüngliche Nachricht----- Von: Christopher Schultz > > [mailto:ch...@christopherschultz.net] Gesendet: Mittwoch, 20. > > Februar 2019 16:41 An: users@tomcat.apache.org Betreff: Re: Logging > > web applications with log4j 1.2 > > > >>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 > >>> > >>> Thomas, > >>> > >>> On 2/20/19 08:00, Thomas Rohde wrote: > >>>> I've some basic questions regarding the usage of log4j 1.2 in > >>>> Tomcat 8.5. > >>>> > >>>> We are running more than one web application in Tomcat. Each > >>>> application uses log4j via slf4j and ships the log4j.jar in > >>>> > >>> WEB-INF/lib. The Tomcat itself uses JULI. > >>> > >>> We are using a common log4j.xml file for configuration. > >>> > >>> The file path is set as system property in CATALINA_OPTS as > >>> follows: -Dlog4j.configuration=/path/to/file/log4j.xml > >>> > >>> 1. Is this a valid setup or are there any side effects in > >>> initialization log4j by the different WebAppClassLoaders? > >> > >> You are not using classpath-based config-file-loading, so it should > >> not be a problem[*]. > >> > >>> 2. We are observing weird things in rolling the files hourly. > >>> The timestamp of the log messages doesn't fit to the timestamp > >>> suffix of the file. Why does this happen? > >> > >> Possibly conflicting time zones, somewhere? Because log4j.jar is in > >> each application's class loader, they CAN have different in-memory > >> configurations. > > No there are no different time zones in use. > > That's what I figured. I've never see anything quite like you describe. I > could imagine that the JVM has one time zone but the shell is using another. > > For example, if the JVM is convinced that the time zone is UTC but when you > are logged-into the server, your shell has TZ=America/Los_Angeles, then > you'll see a ~9 hour difference between file timestamps and the filenames. > Like this: > > $ ls -l logs/ > > - -rw-r--r-- 12345 Feb 19 16:01 log4j.log.2019-02-18 > - -rw-r--r-- 12345 Feb 20 16:00 log4j.log.2019-02-19 > - -rw-r--r-- 12345 Feb 21 16:01 log4j.log.2019-02-20 > > Note how each filename has the name you'd expect, but the timestamp looks a > little odd. If you look into each file, you'd see that e.g. in the 2019-02-19 > file, the timestamps go from 2019-02-19T00:00:00 through 2019-02-19T23:59:59 > but it looks like the file was rotated 8 hours earlier. That's because it was > rotated at 00:00 (PST) as reckoned by the JVM, but at 16:01 in UTC. > > My recommendation would be to set all of your timezones to the same thing. > UTC makes the most sense to me, but that's just my opinion. > Theoretically, all timestamps are interchangeable, right?
Thank you for the hint. We will check that! > > >> [*] While this will work, why would you ever want multiple > >> applications to have their logging configuration all tied together? > >> Why not separate the logging configuration into one config-per web > >> application? OR are you trying to unify all logging into the same > >> file(s )? > > Yes I would like to do that, but I'm not sure how to achieve it > > without putting the log4j.xml into the WAR file. Do you have any hint? > I can think of several ways, but it depends upon how your application > initializes log4j. > > If you specify where the configuration file is, directly, then you can either > change that to somewhere else, or you can replace that filename with a > parameter that you can set in web.xml -- say, in an <init-param>. You *are* > configuring log4j in a ServletContextInitializer, right? > > If you just do "new PropertyConfigurator()" (like I do), then it will search > the parent ClassLoader and that's it. In that case, you'll have to arrange > for the log4j.properties file to be present, there. Placing it in the WAR > file is an option. Another option would be to put the file elsewhere, but > then modify the Tomcat configuration to add another directory to the > ClassLoader, like this: > > <Context> > <Resources> > <PostResources > webAppMount="/" > base="/path/to/app-specific-log-dir" > className="org.apache.catalina.webresources.DirResourceSet" > </Resources> > </Context> > > Then you put your log4j.properties file in /path/to/app-specific-log-dir . Yeah, in the meantime, I have already thougt about this solution. We will do some tests. Thank you! > > Hope that helps, > - -chris > -----BEGIN PGP SIGNATURE----- > Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/ > > iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAlxuv/0ACgkQHPApP6U8 > pFiiTA/+MesYHVHy1lHSzhxLylGC9q/vLXu2wykUQysUBh0GCbHqnftzytV5gKrd > GBwsPbbFSveGcn6VkhL/mJZJPsHAxGWB6pgoK4rYsjw1qVfUeDWr2XeC7AAVNFMC > 0BXyS99u5CC0jlh+/Ps/SZMOZAby/hGfTuoFRD4VT6K3MmgtdAsbGVcci+ycLSLd > tOKWmxglu/0ylEc4fmxBDPygvmve/FD+elfSyqZ8VBri6UTlae++qcsnmBSeus8y > KqiHiZCWrZsn55FBhAsEJXQ1tvluxhpNYrcleEVXM/KZcH/g7eyNGdelFMJ4UVyk > cEM9dfWJdi74RJlZNN03CIWjJawI7IVZg0ghU/2C0ErwXlfjecA2vW0HZE2z/XtO > v+vJW2PXcM/pVef+Af5kf+f8wFGWeAaFVQhwQeSFEZQnG8Mfi8VaQifZd8X+ho9f > SshOywKZ4vDb2VmJrhg3aMwu9Q2BtggA+7fZ0n0/wJJJHj7qC9W8OI35hacSJJ1d > U+USkNNo9vhoF6/wqU+NCMxj7sApEJyIgR4+Vcfl4MFnMaVRthc1WsOiTraW6RuS > G7IJm1z/pSSjqR+Age2/0F/zAAqknjVmCxKzuQIIv66K6PYV4UncRJY0r9bSnMx6 > 43eGJmG+wTcH+R7IAXEi0+r9zVb7UbK6kqpvfD9SpFWD3Ijlb8Y= > =BT+f > -----END PGP SIGNATURE----- --------------------------------------------------------------------- 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