Skip to content

https-github-com-Surachai-kent/log4j-plugins

 
 

Repository files navigation

Copernik.eu Log4j2 plugins

Copernik.eu Log4j2 plugins is a loose set of plugins for the Log4j2 Core logging system.

log4j-tomcat

The log4j-tomcat artifact contains an alternative WebappClassloader that allows a web application to use a common version of the Log4j2 API if it is available on the Tomcat server. To use it:

  • add log4j-tomcat to your application,
  • add a META-INF/context.xml file (cf. defining a context with content:
   <Context>
       <Loader loaderClass="eu.copernik.log4j.tomcat.Log4jWebappClassLoader"/>
   </Context>

The artifact contains also a "${tomcat:...}" lookup that resolves all the classloader.* properties available in Tomcat JULI.

Placeholder Value
${tomcat:catalina.engine.name}
${tomcat:classloader.serviceName}
The name of the Tomcat's Engine container (e.g. "Catalina")
${tomcat:catalina.engine.logger} The logger name used by Tomcat's engine
${tomcat:catalina.host.name}
${tomcat:classloader.hostName}
The name of the Tomcat's Host container (e.g. "localhost")
${tomcat:catalina.host.logger} The logger name used by Tomcat's host
${tomcat:catalina.context.name}
${tomcat:classloader.webappName}
The name of the Tomcat's Context container
${tomcat:catalina.context.logger} The logger name used by Tomcat's context (e.g. by ServletContext#log)

This allows to write a single Log4j2 configuration for all deployed application, e.g.:

<Configuration name="Default">
    <Appenders>
        <File name="FILE"
              fileName="${sys:catalina.base}/logs/${tomcat:catalina.engine.name}/${tomcat:catalina.host.name}/${tomcat:catalina.context.name}.log"/>
    </Appenders>
    <Loggers>
        <Root level="INFO">
            <AppenderRef ref="FILE"/>
        </Root>
    </Loggers>
</Configuration>

License

Copernik.eu Log4j2 plugins is distributed under the Apache License, version 2.0.

About

Log4j2 plugins for Tomcat

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%