-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Michael,

On 12/18/18 13:53, Lemke, Michael  ST/HZA-ZIC2 wrote:
> Thanks, Ryan, this JULI thing actually is what worries me. I don't
> care about tomcat's logging at the moment. It is my webapp's
> logging I can't figure out. It worked on other containers.

Oh, good: you are trying just to manage your own application's logging.

I have this class running as a ServletContextListener:

package xxx;

import javax.servlet.ServletContextListener;
import javax.servlet.ServletContextEvent;

import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.Logger;
import org.apache.log4j.LogManager;

/**
 * A listener to initialize log4j.
 *
 * @author Chris Schultz
 * @version $Revision: 17834 $ $Date: 2015-12-16 11:03:13 -0500 (Wed,
16 Dec 2015) $
 */
public class Log4jListener
    implements ServletContextListener
{
    private Logger logger;

    @SuppressWarnings("unused")
    public void contextInitialized(ServletContextEvent e)
    {
        // Trigger loading of the log4j.properties file from the
classpath.
        new PropertyConfigurator();

        logger = Logger.getLogger(this.getClass());

        logger.info("Log4j initialized");
    }

    public void contextDestroyed(ServletContextEvent e)
    {
        if(LogManager.class.getClassLoader()
           .equals(this.getClass().getClassLoader()))
        {
            if(null != logger)
                logger.info("Log4j was loaded by application
classloader; shutting down.");

            LogManager.shutdown();
        }
        else
        {
            if(null != logger)
                logger.info("Log4j was loaded by some other
ClassLoader; not shutting down.");
        }
    }
}

Calling the PropertyConfigurator constructor causes that class to look
for log4j.properties in various places, including (due to the way the
WebappClassLoader works), WEB-INF/classes. It should also look in the
"top-level" of any application JAR files that are in WEB-INF/lib.

You said that "your JAR file contains log4j.properties". Usually
applications are packaged as WAR files (or exploded WAR directories).
Are you using embedded Tomcat or Spring Boot or anything like that?
Where is your JAR file located?

- -chris

> -----Original Message----- From: Ryan Palmer Sent: Tuesday,
> December 18, 2018 7:49 PM
> 
> Michael,
> 
> Tomcat uses JULI internally. Have you taken necessary steps to
> redirect JULI to log4j?
> 
> Thanks, Ryan
> 
> ________________________________ From: Lemke, Michael ST/HZA-ZIC2
> <lemke...@schaeffler.com> Sent: Tuesday, December 18, 2018 10:20
> AM To: Tomcat Users List Subject: RE: log4j app logging
> 
> On December 18, 2018 6:59 PM Ryan Palmer wrote:
>> 
>> The file needs to be named
>> log4j.properties<http://log4j.properties> (or .xml, .json, etc.)
>> and needs to be in the classpath. You ommitted the 'j'.
> 
> Thanks for spotting this. Unfortunately, this typo was only in the
> email:
> 
> pc# ls src/main/resources/ com  log4j.properties
> 
> 
> So for being in the classpath it is sufficient to have it packaged
> in the jar, isn't it?
> 
> Archive:  myapp-1.1.0-SNAPSHOT.jar Length   Method    Size  Cmpr
> Date    Time   CRC-32   Name --------  ------  ------- ----
> ---------- ----- --------  ---- 0  Stored        0   0% 12-18-2018
> 16:56 00000000  META-INF/ 98  Defl:N       91   7% 12-18-2018 16:56
> 48730e36  META-INF/MANIFEST.MF 0  Stored        0   0% 12-18-2018
> 16:56 00000000  META-INF/maven/ ... 0  Stored        0   0%
> 12-18-2018 16:56 00000000  com/ ... 1123  Defl:N      451  60%
> 12-18-2018 16:56 eea5d81a  log4j.properties
> 
> It ought to be something simple but before further digging into my
> setup details I want to make sure there isn't something special for
> tomcat. Something in ${catalina.base}/conf or conflicts with
> tomcat's logging system.
> 
> 
>> On Dec 18, 2018, at 9:42 AM, "Lemke, Michael ST/HZA-ZIC2" wrote:
>> 
>> I have an old webapp that uses log4j 1.2 and which I am trying to
>> deploy on tomcat. For the heck of it I can't get tomcat to use
>> the log4.properties<http://log4.properties> file. What am I doing
>> wrong?
>> 
>> tomcat 9.0.6 is installed as a Windows service and does serve my
>> webapp, so the app is working fine. The project is mavenized, I
>> put log4.properties<http://log4.properties> to src/main/resources
>> and it ends up in the jar file of my application. Is there
>> anything special that needs to be done?
>> 
>> ________________________________
>> 
>> 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
> 
> 
> ---------------------------------------------------------------------
>
> 
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
> 
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAlwZUNgACgkQHPApP6U8
pFjT8w/9GjwEULflsNS+pW/6O+ADz7jHFr6FtXpv9v3N1AtdLXAt4u0tlqhJyLCg
uV0nMDkpEMhpFQVaOXwOLO/0Ygnmam9ty4dw457ePhgwEWnupg888fFHQibYqJ07
dUJ93AiWcSITt2JtH4Xlo/QeOzUgViHRP1mB5fL/Qrh163hj27MlQzg876VGhDLe
qIlZs1sPl3KWx9G7b6H1XUQG2BIYlVWYAOTSmW8xNdaYUXUEjWwtY9eVpigm1CKO
57iajYz1YBoSAViXpcNrVB0MSdcKIP64xTlDXsK45Sos7vTnS7V49O7wBWw8QRDc
HpekdyzqDFZAXrqFjif5NLrboGKN0OW+piPNzbQuz6Dh/dyYTNUx7JZRYIg/mwqd
pznunwHItCnIKQjmKuIPmWTM0fqRvyJom9HCM14xbSHBUG+p0sebyI/J8w8iZWRO
ftmBY7n654DohS0tZry6nQdsq/jGPnrxnj+psFfelV6vQ7DDx2eOak4tEoB9HTaZ
Zxm/zBrn9Yppb2kZ4xXc6wRdj59pPyUv2EpcCaGN7G8Yr0n7h1O3UTwcYr8D59Aw
FugBtgsf0mCoAAiYNo91WcUsQ3xJmUef4RtTd5VeOuTaA29azmV9IpYzjKN6gWOg
XooQL5PA9FI5w0mJZFquXfrIxuIz4T4Xyy4klaDvCKG5jvnutzM=
=vWAH
-----END PGP SIGNATURE-----

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

Reply via email to