Setting Hibernate Logging Provider with Version 6.1 - java

I am using Hibernate 6.1.2. I'd like to log use the default JDK logging provider. According to a documentation for 5.4, this can be done like this:
public class TestSL4JBug {
public static void main(String[] args) {
System.setProperty("org.jboss.logging.provider", "jdk");
jakarta.persistence.Persistence.createEntityManagerFactory("myPersistence");
}
}
I looked for a similar explanation in newer documentations, but I did not find it.
Alas, if I am testing the minimal example above, I get this:
...
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.
MLog initialization issue: slf4j found no binding or threatened to use its (dangerously silent) NOPLogger. We consider the slf4j library not found.
...
To me, this looks like Hibernate tries to load SLF4J and fails. I have, of course, found guides that say I should add the SLF4J dependency, but that is not what I want.
So my question is: How do I configure Hibernate 6.1.2 to log with JDK logging? Has the property changed, or should I use a better way to set it?

I realized that it was not vanilla Hibernate that caused the error. I am also using hibernate-spatial and consequently geolatte-geom. That one is not using JBoss logging and instead always goes through SLF4J. So even though Hibernate went through JDK logging, SLF4J was still loaded. I have now unhappily added slf4j-jdk14 and the error is gone. It's still more layers and source code sources than I am happy with, but probably a lot less than in other programming ecosystems.

Related

configure gradle slf4j bindings for java test task

I'm in the process of migrating my tests to use Junit5 and I noticed that somehow my logs stopped working.
Before I was defining my logs with a simple simplelogger.properties inside by test/resources folder.
But this no longer working.
I was reading the gradle documentation and I see a lot of information about it and I can define some logs using the test logging container.
Anyway this somehow does not seem to allow me to do what I want.
I'm looking if there is anything I can add to my test definition that let's me define the log4j configuration folder/file
test {
useJUnitPlatform()
maxHeapSize = '2G'
reports {
junitXml.enabled = true
html.enabled = true
}
timeout = Duration.ofMinutes(30)
testLogging {
showStandardStreams true
exceptionFormat 'full'
events "PASSED", "SKIPPED", "FAILED", "STANDARD_OUT", "STANDARD_ERROR"
}
systemProperty 'bla', 'bla'
}
Is there a way I can define a log4.properties file or a simplelogger.properties file and tell the jvm where to find it but instead of using the JVM parameters I would use some gradle configuration?
Also I notice when my tests start that it finds multiple SLF4J bindings which I'm not sure how to work around.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/.gradle/caches/7.4.2/generated-gradle-jars/gradle-api-7.4.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.2.11/4741689214e9d1e8408b206506cbe76d1c6a7d60/logback-classic-1.2.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-log4j12/1.7.30/c21f55139d8141d2231214fb1feaf50a1edca95e/slf4j-log4j12-1.7.30.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.gradle.internal.logging.slf4j.OutputEventListenerBackedLoggerContext]
Is there any good documentation for this? I seem to not find what I need in the official documentation or examples.
The source of the problem might be something like this (i'm using the gradle-groovy plugin also):
SLF4J: multiple SLF4J bindings with Gradle Plugin
if nothing else works I'm thinking of trying something like this (to override it on the jvm args):
How to pass args to JVM which runs tests with Gradle
log4j configuration via JVM argument(s)?

"No SLF4J providers were found" after adding slf4j-api-2.0.0-alpha1.jar to the project structure and the slf4j dependency to the pom.xml

I am trying to use Apache Beam with Java using IntelliJ and I get the
"SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation" error
when I have already added the slf4j-api-2.0.0-alpha1.jar to the project structure and the slf4j dependency to the pom.xml
Here are some screenshots for more context:
You have added slf4j-api module, which is the API for adding logging statements to your code. It does not actually do anything with the logs, so they will be dropped. You will need to choose a backend such as slf4j-jdk14 or slf4j-logback13.
The exception in your screenshot is not related.
First of all, the SLF4J messages are only warnings and can be ignored. They most probably have nothing to do with Exception in thread "main".
They mean that some code is trying to use slf4j api, but no implementation handles what to do with these logs. You may get rid of the warnings by adding to your classpath a working implementation of the SLF4j, e.g. org.slf4j:slf4j-simple to make the logs show in the console or org.slf4j:slf4j-nop to ignore any logging explicitly or one of a number of other logging framework integration options.
You have to remove test scope in your dependency of slf4j simple dependency. This could be one of the reasons.

Java SLF4J warning when starting hive on WINDOWS 10

I am trying to start HIVE 3.1.2 on Hadoop 3.3.0 on my windows 10 PC for training purpose (yes I know linux is better ;-) but someone has to do it anyway). I have the following error message
it looks related to how SLF4J works (I guess) but since I am not a java (or any other language) dev I have no clue how to fix it
For what it worth I do not have an IT background so be gentle and talk to me as if I was 10y/o
Could any one help (BTW it is running on java 8)
$ hive
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/zztop/hadoop/hive/lib/log4j-slf4j-impl-2.14.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/zztop/hadoop/hive/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/zztop/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.apache.logging.log4j.util.PropertiesUtil
at org.apache.logging.log4j.status.StatusLogger.<clinit>(StatusLogger.java:71)
at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:60)
at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:45)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:30)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:281)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:301)
at org.apache.hadoop.util.RunJar.<clinit>(RunJar.java:55)
What you are seeing is a misconfiguration of the logging framework, which it detects and complains about, including a link to http://www.slf4j.org/codes.html#multiple_bindings which explains the following:
SLF4J API is designed to bind with one and only one underlying logging
framework at a time. If more than one binding is present on the class
path, SLF4J will emit a warning, listing the location of those
bindings.
When multiple bindings are available on the class path, select one and
only one binding you wish to use, and remove the other bindings. For
example, if you have both slf4j-simple-2.0.0-alpha0.jar and
slf4j-nop-2.0.0-alpha0.jar on the class path and you wish to use the
nop (no-operation) binding, then remove slf4j-simple-2.0.0-alpha0.jar
from the class path.
It is not uncommon to see this problem, when combining multiple things together that bring their own logging backend. The solution is to figure out why (the jars are listed) and only leave one binding.

The Java Wiki Bot Framework logging

I am using The Java Wiki Bot Framework to do changes in a mediawiki website using java, and it works fine. The only problem is that the JWBF produces a a huge volume of debugging information in the console of my application that is overshadowing my output and make it hard to find, visually. is their anyway that I could stop the logging for JWBF? BTW, JWBF uses SL4J for logging.
This is a slf4j related topic. If no logger binding is defined, you see the following
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.
If you add a binding e.g. Logback, you can reduce logging output. Your logback.xml should contains a line like
...
<logger name="net.sourceforge.jwbf" level="ERROR"/>
...
For more details see Logback configuration

Does slf4j use commons-logging implementation by default?

I have only worked with log4j in the past. Now I am scouting a new project and noticing that it uses slf4j 1.7.2. I understand it is only an API specification which provides a simplified interface (AKA facade) to various implementations that conform to it, such as java.util.logging, log4j and logback. However, I noticed that commons-logging wasn't mentioned in the list on the API web site, however, its jar was in this app's classpath. When I removed it from the classpath to check whether it was the used implemetation, I confirmed that it indeed was:
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.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
Is commons-logging indeed the default implementation for slf4j? Because their documentation says:
If no binding is found on the class path, then SLF4J will default to a no-operation implementation.
at the above linked page. And even though I have slf4j-nop-1.7.2.jar in the classpath, which I am guessing the default implementation referred to above is, I still get the exception asking for org/apache/commons/logging/LogFactory if the commons is not in the classpath, so I am confused.
A clarification would be appreciated.
You need a combination of the binding jar AND the logging implementation (JCL in this case) on the classpath.
Binding with a logging framework at deployment time
commons-logging is not the default, but if you have slf4j-jcl-1.7.2.jar on your classpath, it will try to use that. So if you therefore remove JCL from your path, it will complain that it can't find the classes.
slf4j-nop-1.7.2.jar is the no-op "SLF4J bindings" jar, not an implementation in itself.

Categories