[GLASSFISH-6666] Ability to log to SLF4J Created: 29/Oct/08  Updated: 06/Jun/12

Status: Open
Project: glassfish
Component/s: logging
Affects Version/s: 9.1peur2
Fix Version/s: not determined

Type: Improvement Priority: Major
Reporter: cowwoc Assignee: naman_mehta
Resolution: Unresolved Votes: 25
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: All
Platform: All

Issuezilla Id: 6,666


I'm trying to get Glassfish to log to slf4j instead of Java Logging but I've run
into a dead end: http://forums.java.net/jive/thread.jspa?threadID=52441&tstart=30

It would be great if the Glassfish logging mechanism was plugable or at the very
least if I could somehow get access to the original System.out object to pass
into slf4j.

Comment by niklash [ 31/Dec/08 ]
      • Issue 6666 has been confirmed by votes. ***
Comment by cowwoc [ 13/Feb/11 ]

Can someone from the Glassfish team please comment on this issue?

Comment by cowwoc [ 13/Feb/11 ]

http://hwellmann.blogspot.com/2010/12/glassfish-logging-with-slf4j-part-2.html contains a workaround for redirecting all Glassfish logs onto slf4j. I'm still looking for a way to redirect on a per-webapp basis.

Comment by cinhtau [ 14/Feb/11 ]

Per webapp basis you have to put an independent logback.xml and invoke JoranConfigurator directly. That's the trick. See http://logback.qos.ch/manual/configuration.html

Comment by cowwoc [ 14/Feb/11 ]

I understand, but you're still requiring me to place slf4j libraries in the global location and hook all java.util.logging instances to slf4j whether they want it or not.

Comment by orair [ 26/Jan/12 ]

If the logging libraries are on a shared place, configure Glassfish per webapp basis will probably need to create contexts. See http://logback.qos.ch/manual/loggingSeparation.html#ContextJNDISelector for more information.

Comment by Tom Mueller [ 06/Mar/12 ]

Bulk update to change fix version to "not determined" for all issues still open but with a fix version for a released version.

Comment by cowwoc [ 01/Jun/12 ]

I ended up redirecting slf4j to java.util.logging (JUL). To do this simply use slf4j-jdk14 as your logger implementation in place of logback. Unfortunately, this trades off one problem for another.

On the one hand, your logging is unified. On the other hand, you inherit all the problems associated with JUL. You cannot use any logback-specific features. You cannot use logback.xml to configure your logging. In fact, you cannot even configure different logging rules per webapp (see GLASSFISH-18776). I ended up with the following code in my ServletContextListener:

public void contextInitialized(ServletContextEvent servletContextEvent)

  // WORKAROUND: http://java.net/jira/browse/GLASSFISH-18776

It doesn't solve the problem of all webapps sharing the same logging configuration, but at least now the configuration is packaged in the webapp itself (as opposed to logging.properties in Glassfish's installation directory).

Comment by jthoennes [ 06/Jun/12 ]

We managed to deploy SLF4J as an OSGi bundle. So you can deploy it in the normal way instead of in the lib directory.
And the configuration could be done in the bundle activator.

Generated at Sun Mar 26 14:15:06 UTC 2017 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.