Minor improvements in logging setup suggested by Walter.
authornlevitt <nlevitt@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Thu, 11 Mar 2004 20:41:36 +0000 (20:41 +0000)
committernlevitt <nlevitt@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Thu, 11 Mar 2004 20:41:36 +0000 (20:41 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@907 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/log/LoggingContextListener.java

index 1b29773..1e6ad30 100644 (file)
@@ -95,6 +95,9 @@ public class LoggingContextListener implements ServletContextListener {
        // tomcat calls this before the servlet init()s, but is that guaranteed?
        public void contextInitialized(ServletContextEvent sce)
        {
+               //Silliness to get around xmlsec doing its own configuration, ie: we might need to override it
+               Init.init();
+
                ConsoleAppender rootAppender = new ConsoleAppender();
                rootAppender.setWriter(new PrintWriter(System.out));
                rootAppender.setName("stdout");
@@ -105,12 +108,6 @@ public class LoggingContextListener implements ServletContextListener {
                Logger.getRootLogger().setLevel((Level) Level.INFO);
                rootAppender.setLayout(new PatternLayout("%d{ISO8601} %-5p %-41X{serviceId} - %m%n"));
 
-               Logger.getLogger("org.apache.xml.security").setLevel((Level) Level.OFF);
-               Logger.getLogger("org.opensaml").setLevel((Level) Level.OFF);
-
-               //Silliness to get around xmlsec doing its own configuration, ie: we might need to override it
-               Init.init();
-
                try {
                        Document originConfig = OriginConfig.getOriginConfig(sce.getServletContext());
                        loadConfiguration(originConfig);
@@ -133,6 +130,7 @@ public class LoggingContextListener implements ServletContextListener {
        protected void loadConfiguration(Document originConfig) throws ShibbolethConfigurationException
        {
                NodeList itemElements = originConfig.getDocumentElement().getElementsByTagNameNS(ShibbolethOriginConfig.originConfigNamespace, "Logging");
+
                if (itemElements.getLength() > 1) 
                {
                        log.warn("Encountered multiple <Logging> configuration elements. Using first one.");
@@ -142,6 +140,7 @@ public class LoggingContextListener implements ServletContextListener {
                {
                        Node loggingNode = itemElements.item(0);
                        Node errorLogNode = null;
+                        boolean encounteredLog4JConfig = false;
 
                        for (int i = 0; i < loggingNode.getChildNodes().getLength(); i++)
                        {
@@ -150,6 +149,7 @@ public class LoggingContextListener implements ServletContextListener {
                                if ("Log4JConfig".equals(node.getNodeName()))
                                {
                                        doLog4JConfig(node);
+                                        encounteredLog4JConfig = true;
                                }
                                else if ("TransactionLog".equals(node.getNodeName()))
                                {
@@ -167,6 +167,18 @@ public class LoggingContextListener implements ServletContextListener {
                        {
                                configureErrorLog(errorLogNode);
                        }
+                       else
+                       {
+                               // started out at INFO for logging config messages
+                               Logger.getRootLogger().setLevel((Level) Level.WARN);
+                       }
+
+                       // turn these off by default
+                       if (!encounteredLog4JConfig)
+                       {
+                               Logger.getLogger("org.apache.xml.security").setLevel((Level) Level.OFF);
+                               Logger.getLogger("org.opensaml").setLevel((Level) Level.OFF);
+                       }
                }
        }