webapp-jul-to-slf4j

Parent POM for all skuzzle GitHub Projects

License

License

Categories

Categories

SLF4J Application Layer Libs Logging
GroupId

GroupId

de.skuzzle.slf4j
ArtifactId

ArtifactId

webapp-jul-to-slf4j
Last Version

Last Version

1.7.12
Release Date

Release Date

Type

Type

jar
Description

Description

webapp-jul-to-slf4j
Parent POM for all skuzzle GitHub Projects

Download webapp-jul-to-slf4j

How to add to project

<!-- https://jarcasting.com/artifacts/de.skuzzle.slf4j/webapp-jul-to-slf4j/ -->
<dependency>
    <groupId>de.skuzzle.slf4j</groupId>
    <artifactId>webapp-jul-to-slf4j</artifactId>
    <version>1.7.12</version>
</dependency>
// https://jarcasting.com/artifacts/de.skuzzle.slf4j/webapp-jul-to-slf4j/
implementation 'de.skuzzle.slf4j:webapp-jul-to-slf4j:1.7.12'
// https://jarcasting.com/artifacts/de.skuzzle.slf4j/webapp-jul-to-slf4j/
implementation ("de.skuzzle.slf4j:webapp-jul-to-slf4j:1.7.12")
'de.skuzzle.slf4j:webapp-jul-to-slf4j:jar:1.7.12'
<dependency org="de.skuzzle.slf4j" name="webapp-jul-to-slf4j" rev="1.7.12">
  <artifact name="webapp-jul-to-slf4j" type="jar" />
</dependency>
@Grapes(
@Grab(group='de.skuzzle.slf4j', module='webapp-jul-to-slf4j', version='1.7.12')
)
libraryDependencies += "de.skuzzle.slf4j" % "webapp-jul-to-slf4j" % "1.7.12"
[de.skuzzle.slf4j/webapp-jul-to-slf4j "1.7.12"]

Dependencies

compile (2)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.12
org.slf4j : jul-to-slf4j jar 1.7.12

provided (1)

Group / Artifact Type Version
javax.servlet : javax.servlet-api jar 3.1.0

Project Modules

There are no modules declared in this project.

webapp-jul-to-slf4j

Little helper library allowing to enable JDK logger bridging during deployment time of a web application. Please make sure you understand the implications of briding the JDK logger that are described in the slf4j documentation.

Maven Dependency

<dependency>
    <groupId>de.skuzzle.slf4j</groupId>
    <artifactId>webapp-jul-to-slf4j</artifactId>
    <version>1.7.12</version>
</dependency>

Why?

The design of slf4j is all centered around deployment time flexibility. For most slf4j extensions it is sufficient to place a certain jar into the class path and you are done. However, for bridging the JDK logger to redirect it to slf4j, you currently have to write additional setup code to have it run properly.

This extension is for use in web applications that are run in a Java EE 6 compliant container. Those containers will query the ServiceLoader for service providers of the type ServletContainerInitializer. This library implements such a listener to perform the necessary steps for redirecting the JDK logger to slf4j.

Usage

Simply put this library into the class path of your web application. As described above, it will then automatically be recognized by the servlet container during startup.

Log messages sent to the JDK logger are only redirected to slf4j, if the respective logger is enabled. Besides configuring the redirect to slf4j, this library will set the log level of the JDK root logger to ALL in order to have it redirect all messages to slf4j.

FAQ

JDK logging bridge with tomcat and eclipse

When using slf4j's JDL bridge with a tomcat started from eclipse you are very likely to run into the following strange error:

java.lang.ClassCircularityError: java/util/logging/LogRecord
	at org.slf4j.bridge.SLF4JBridgeHandler.getSLF4JLogger(SLF4JBridgeHandler.java:198)
	at org.slf4j.bridge.SLF4JBridgeHandler.publish(SLF4JBridgeHandler.java:287)
	at java.util.logging.Logger.log(Logger.java:731)
	at java.util.logging.Logger.doLog(Logger.java:754)
	at java.util.logging.Logger.logp(Logger.java:919)
	at org.apache.juli.logging.DirectJDKLog.log(DirectJDKLog.java:183)
	at org.apache.juli.logging.DirectJDKLog.debug(DirectJDKLog.java:106)
	at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:369)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:689)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:321)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455)

This is due to the fact that tomcat, when being started using its startup script, replaces the JDK's LogManager for an own implementation. To achieve the same when running tomcat from eclipse, you need to edit its launch configuration and add the following line:

-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager

Versions

Version
1.7.12