I am struggling printing any log messages generated by SLF4J out of GlassFish 6 or GlassFish 7 application server.
I use org.slf4j:slf4j-api
dependency in my projects myself. I might change it to JUL or System.Logger but in addition to that I use a couple of libraries that log with SLF4J (org.apache.httpcomponents.client5:httpclient5
, org.eclipse.jgit:org.eclipse.jgit
, org.apache.tika:tika-core
or org.apache.activemq:activemq-client
to name a few).
I known, that copying SLF4J- and Logback-JARs to endoresed directory is not possible anymore since endorsed functionality is gone since Java 9.
But I'm sure it must be possible to get this to work. I can not imagine that's not possible to use any of these libraries in GlassFish server anymore given that SLF4J is #2 in most popular libraries in maven.
In GlassFish Administration Guide it is said that
Although application components can use other logging frameworks as SLF4J or LOG4J2, we recommend to use the Java Util Logging Framework or even better it’s latest facade System.Logger.
In an issue in the GlassFish project slf4j-api not working with Glassfish 6 #24138 user dmatej confirms the missing endorsed problem (the issue itself is about an dependency problem between SLF4J version 1 bundled with a GlassFish library). But he writes
Addition of another logging framework is not possible on the server level, but you can use whatever you need in you war/ear file - there should go application dependencies.
I assume that I need to add an SLF4J implementation in my project dependencies.
In the mentioned ticket the user sysmat uploaded a example project as a ZIP file (post). Despite of his actual problem with the SLF4J API version 2 he states that «_it works, using_» API version 1.
So when I downloaded the project and tried to run it on a freshly unzipped GlassFish 6.2.5 (also tried with GlassFish 7.0.7) I got no log messages when accessing the v1 service. Instead I read in the logs
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".|#]
SLF4J: Defaulting to no-operation (NOP) logger implementation|#]
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.|#]
I even tried not to use ch.qos.logback:logback-classic
as an implementation but org.slf4j:slf4j-jdk14
and changed the logging.properties
to set all levels to FINE
. Nothing.
So to summarize my findings
It seems I'm the only person using GlassFish together with SLF4J or (even worse because embarrassing) I'm the only person who doesn't get this to work.
there’s really an issue with using SLF4J with GlassFish 6 and 7. The GlassFish team is aware of this, here’s the issues to track progress: https://github.com/eclipse-ee4j/glassfish/issues/24138#issuecomment-1675488136
The good news is that it’s very close to get fixed. The trouble is that an old version of SLF4J is used in the xmlsec dependency. This is now fixed in the latest version of xmlsec and soon GlassFish will upgrade to this new version and fix issue with SLF4J you encounter.
Meanwhile, somebody confirmed that GlassFish compiled from this branch fixes this issue: https://github.com/dmatej/glassfish/tree/slf4j
User sysmat else suggested to bundle 2 xmlsec related modules into a single module and hide slf4j in it as an internal dependency, not visible to deployed applications. But nobody has tried it yet or not reported how to do it successfully.
Edit: Since GlassFish 7.0.10, slf4j works without issues.