Good. I got this and learned a lot in this process.
TL DR:
Under the following assumptions ...
- Recording parameters are not set explicitly.
- The only JAR log related paths to the classes are the jboss logs (i.e. no slf4j, log4j, etc.).
... Hibernate will automatically select JDK logging through JBoss logging , and java.util.logging can be used to control the log level. Therefore, setting the log level of all JDK logs to SEVERE , at the root logger level (it doesn’t matter if you do this before or after Hibernate initialization, see below) successfully stops the SHOW WARNING commands:
LogManager.getLogManager().getLogger("").setLevel(Level.SEVERE);
However, this is a shotgun approach that sets the log level for all registered Logger for which their level is set to null (inherited from the parent).
JDK Protocol Notes
I came to the above solution:
- Reading the doc log several times until it dies, and without comparing this information with what was in my class, evidence showed the JDK log was used.
- Looked through a list of log names with
LogManager#getLoggerNames() . It was a lot from Hibernate, this confirmed point 1. - I tried to find the registrar responsible for
SHOW WARNINGS , but could not. I know that this is not "org.hibernate.SQL" (changing this level of the log has no effect), and it is not "org.hibernate" (this log does not actually exist). - I printed out the current log levels for all of them and noticed that they are all
null (inherit from parent). - I printed out the hierarchy and saw that the root logger (name ") was the only one that had the log level set, so I set this log level. Note that since Hibernate logs are usually set to" inherit ", it doesn't matter if you run is this before or after setting up Hibernate: if you do this before you get the registration, if you do it after you still see that it is displayed during initialization and probably a couple more
SHOW WARNING will be issued, but this doesn't really matter.
So, as I came to the above, and this leaves the following negligence in my decision:
- The shotgun approach is not entirely accurate which registrar is responsible, so they are all disabled.
- Confused by the lack of "org.hibernate".
- This only works when using the JDK journal, which relies on the above assumptions. Including another supported logging structure in your classpath may cause Hibernate to choose a different structure, which makes the solution ineffective.
- I just tried
SEVERE and checked that it works. Different levels of logs may also work, but I have not tested.
Other notes
I tried to explicitly find out which of the sleeping Hibernate was automatically selected, but could not determine how to do this (does anyone know?). My only wild hunch was something in ServiceRegistry , but there didn't seem to be anything related to the Service journal, or at least I could not find it.
In general, it is much more predictable to explicitly tune the logger and then tune it according to its documentation, because, for example, the above solution breaks simply by adding another JAR to the class path. However, for quick / one-time / non-essential projects where you simply collapse configuration files, etc., This is apparently the easiest way to cut out SHOW WARNING commands.
source share