Преглед изворни кода

This seems to keep jersey from logging warning messages

By putting <listener-class>password.pwm.util.PwmServletContextListener</listener-class> at the top of the web.xml file, it seems we can get the log level set for Jersey soon enough before other logging calls are made.  From what I've read, you really can't modify java util logging configuration once it's been used.

This seems to do the trick on my system.
James Albright пре 9 година
родитељ
комит
3c7dbcb524

+ 1 - 1
pom.xml

@@ -338,7 +338,7 @@
         <dependency>
             <groupId>org.glassfish.jersey.containers</groupId>
             <artifactId>jersey-container-servlet</artifactId>
-            <version>2.22.1</version>
+            <version>2.22.2</version>
         </dependency>
         <dependency>
             <groupId>org.jasig.cas.client</groupId>

+ 21 - 0
src/main/java/password/pwm/util/PwmServletContextListener.java

@@ -0,0 +1,21 @@
+package password.pwm.util;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+public class PwmServletContextListener implements ServletContextListener {
+
+    @Override
+    public void contextInitialized(ServletContextEvent sce) {
+        // Doing this here so the level will be set before any calls are made to LogManager or Logger.
+        Logger.getLogger("org.glassfish.jersey").setLevel(Level.SEVERE);
+    }
+
+    @Override
+    public void contextDestroyed(ServletContextEvent sce) {
+    }
+
+}

+ 2 - 2
src/main/java/password/pwm/util/logging/PwmLogManager.java

@@ -98,8 +98,8 @@ public class PwmLogManager {
 
         initFileLogger(config, fileLogLevel, pwmApplicationPath);
 
-        // disable java's logging altogether, since you can't seem to change the log level for Jersey programmatically, and have it stick.
-        java.util.logging.LogManager.getLogManager().reset();
+        // disable jersey warnings.
+        java.util.logging.Logger.getLogger("org.glassfish.jersey").setLevel(java.util.logging.Level.SEVERE);
     }
 
     private static void initConsoleLogger(

+ 3 - 0
src/main/webapp/WEB-INF/web.xml

@@ -28,6 +28,9 @@
     <display-name>PWM Password Management</display-name>
     <!-- <distributable/> Clustering/Session replication is not supported -->
     <description>Password Management Servlet</description>
+    <listener>
+        <listener-class>password.pwm.util.PwmServletContextListener</listener-class>
+    </listener>
     <context-param>
         <description>
             Explicit location of application working directory. If a relative path is specified, it is relative to the