Patch from Chad that does default log configuration when the <Logging/> element isn...
authorwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Thu, 19 May 2005 03:06:31 +0000 (03:06 +0000)
committerwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Thu, 19 May 2005 03:06:31 +0000 (03:06 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@1527 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/idp/IdPResponder.java
src/edu/internet2/middleware/shibboleth/log/LoggingInitializer.java

index 61a66ef..818de45 100644 (file)
@@ -108,13 +108,16 @@ public class IdPResponder extends HttpServlet {
                                } else {
                                        Element loggingConfig = (Element) itemElements.item(0);
                                        LoggingInitializer.initializeLogging(loggingConfig);
-                                       transactionLog = Logger.getLogger("Shibboleth-TRANSACTION");
-                                       log = Logger.getLogger(IdPResponder.class);
-                                       MDC.put("serviceId", "[IdP] Core");
-                                       log.info("Initializing Identity Provider.");
                                }
+                       } else {
+                               LoggingInitializer.initializeLogging();
                        }
 
+                       transactionLog = Logger.getLogger("Shibboleth-TRANSACTION");
+                       log = Logger.getLogger(IdPResponder.class);
+                       MDC.put("serviceId", "[IdP] Core");
+                       log.info("Initializing Identity Provider.");
+
                        // Load global configuration properties
                        configuration = new IdPConfig(idPConfig.getDocumentElement());
 
@@ -285,7 +288,7 @@ public class IdPResponder extends HttpServlet {
                SAMLRequest samlRequest = null;
                try {
                        try {
-                               samlRequest = binding.receive(request,1);
+                               samlRequest = binding.receive(request, 1);
                        } catch (SAMLException e) {
                                log.fatal("Unable to parse request: " + e);
                                throw new SAMLException("Invalid request data.");
index fea1126..2a21f3a 100644 (file)
@@ -28,6 +28,7 @@ package edu.internet2.middleware.shibboleth.log;
 import java.net.MalformedURLException;
 import java.net.URL;
 
+import org.apache.log4j.ConsoleAppender;
 import org.apache.log4j.DailyRollingFileAppender;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
@@ -97,6 +98,8 @@ public class LoggingInitializer {
                        }
                        Element txLogConfig = (Element) txLogElems.item(0);
                        configureTransactionLog(txLogConfig);
+               } else {
+                       configureTransactionLog();
                }
 
                NodeList sysLogElems = configuration.getElementsByTagNameNS(IdPConfig.configNameSpace, "ErrorLog");
@@ -107,6 +110,8 @@ public class LoggingInitializer {
                        }
                        Element sysLogConfig = (Element) sysLogElems.item(0);
                        configureSystemLog(sysLogConfig);
+               } else {
+                       configureSystemLog();
                }
 
                NodeList log4jElems = configuration.getElementsByTagNameNS(IdPConfig.configNameSpace, "Log4JConfig");
@@ -121,6 +126,30 @@ public class LoggingInitializer {
        }
 
        /**
+        * Initialize the logs for the Shibboleth-TRANSACTION log, edu.internet2.middleware.shibboleth, and org.opensaml
+        * logs. Output is directed to the standard out with the the transaction log at INFO level and the remainder at
+        * warn.
+        */
+       public static void initializeLogging() {
+
+               configureTransactionLog();
+               configureSystemLog();
+       }
+
+       /**
+        * Configured the transaction log to log to the console at INFO level.
+        */
+       private static void configureTransactionLog() {
+
+               ConsoleAppender appender = new ConsoleAppender(new PatternLayout(txLogLayoutPattern),
+                               ConsoleAppender.SYSTEM_OUT);
+               Logger log = Logger.getLogger("Shibboleth-TRANSACTION");
+               log.setAdditivity(false); // do not want parent's messages
+               log.setLevel(Level.INFO);
+               log.addAppender(appender);
+       }
+
+       /**
         * Configures the transaction log.
         * 
         * @param configuration
@@ -160,6 +189,23 @@ public class LoggingInitializer {
        }
 
        /**
+        * Configures the standard system log to log messages from edu.internet2.middleware.shibboleth and org.opensaml to
+        * the console at WARN level.
+        */
+       private static void configureSystemLog() {
+
+               ConsoleAppender appender = new ConsoleAppender(new PatternLayout(sysLogLayoutPattern),
+                               ConsoleAppender.SYSTEM_OUT);
+               Logger shibLog = Logger.getLogger("edu.internet2.middleware.shibboleth");
+               shibLog.setLevel(Level.WARN);
+               shibLog.addAppender(appender);
+
+               Logger openSAMLLog = Logger.getLogger("org.opensaml");
+               openSAMLLog.setLevel(Level.WARN);
+               openSAMLLog.addAppender(appender);
+       }
+
+       /**
         * Configures the system-wide IdP log.
         * 
         * @param configuration
@@ -237,4 +283,4 @@ public class LoggingInitializer {
                        DOMConfigurator.configure(url);
                }
        }
-}
+}
\ No newline at end of file