Search code examples
hibernatejpalogback

Java code to override hibernate logging level from logback.xml


My company produces a Java application that we ship to customers. (It's not a hosted application.) The customer is able to modify the logback.xml file to adjust the logging levels of the application code and of various libraries that the application uses.

We want to preserve this ability, but with one restriction. We want to make it so that the customer is unable to set the log level for org.hibernate (and for the many packages that are children/descendants of org.hibernate) to debug. This is because we need to ensure that PII (personally-identifiable information) is not logged, and hibernate's debug-level logging would cause PII to be logged.

There are 100s of classes in the application that create Logger objects, and it would not be feasible to modify every one of those Loggers individually. Is there a way, using Java code in the application, to set the log level of org.hibernate (and its sub-packages) to info at the application level?


Solution

  • You can do something like;

    java.util.logging.Logger.getLogger("org.hibernate").setLevel(Level.SEVERE);