cleanup, add checks to arguments and responses, add log statements
[java-idp.git] / src / edu / internet2 / middleware / shibboleth / serviceprovider / ContextListener.java
index 6557b83..55974e6 100644 (file)
@@ -25,6 +25,7 @@ import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
 import javax.servlet.UnavailableException;
 
+import org.apache.log4j.ConsoleAppender;
 import org.apache.log4j.FileAppender;
 import org.apache.log4j.Layout;
 import org.apache.log4j.Level;
@@ -46,32 +47,49 @@ import edu.internet2.middleware.commons.log4j.ThreadLocalAppender;
  * that you can move logic around as needed.
  */
 public class ContextListener implements ServletContextListener {
-       
-
-       // Initialization, parsing files, and setting up
+    
+    //TODO: Change before release
+       private static final Level defaultLogLevel = Level.INFO;
+    
+    // Initialization, parsing files, and setting up
        public static final String SHIBBOLETH_INIT = "shibboleth.init";
-       private Logger initLogger = Logger.getLogger(SHIBBOLETH_INIT);
+       private static  Logger initLogger = Logger.getLogger(SHIBBOLETH_INIT);
+       private static  Logger initLogger2 = Logger.getLogger("edu.internet2.middleware.shibboleth.xml");
        
        // Authentication and Attribute processing, including SAML, Trust, 
        // Metadata, etc. Because the SP doesn't control all the code, it is
        // based on real classnames
-       private Logger clientLogger = Logger.getLogger("edu.internet2.middleware");
-       private Logger samlLogger = Logger.getLogger("org.opensaml");
+       private static Logger clientLogger = Logger.getLogger("edu.internet2.middleware");
+       private static Logger samlLogger = Logger.getLogger("org.opensaml");
        
        // Requests from the Resource Manager only touch the RequestMapper
        // and Session Cache
        public static final String SHIBBOLETH_SERVICE = "shibboleth.service";
-       private Logger serviceLogger = Logger.getLogger(SHIBBOLETH_SERVICE);
+       private static Logger serviceLogger = Logger.getLogger(SHIBBOLETH_SERVICE);
 
 
        public void contextInitialized(ServletContextEvent servletContextEvent) {
                ServletContext servletContext = servletContextEvent.getServletContext();
                Init.init(); // Let XML Security go first
                
+               
                Layout initLayout = new PatternLayout("%d{HH:mm} %-5p %m%n");
+               
                ThreadLocalAppender threadAppender = new ThreadLocalAppender();
                threadAppender.setLayout(initLayout);
+               threadAppender.setName("ThreadAppender");
+               
+               ConsoleAppender consoleAppender= new ConsoleAppender(initLayout,ConsoleAppender.SYSTEM_OUT);
+               consoleAppender.setName("SPConsoleAppender");
+               
                clientLogger.addAppender(threadAppender);
+               clientLogger.addAppender(consoleAppender);
+               clientLogger.setLevel(defaultLogLevel);
+               
+               initLogger.addAppender(consoleAppender);
+               initLogger.setLevel(defaultLogLevel);
+               
+               initLogger2.setLevel(defaultLogLevel);
                
                // The init log location is represented as a URL in the web.xml
                // We have to change this int a fully qualified path name
@@ -82,8 +100,9 @@ public class ContextListener implements ServletContextListener {
                                File initLogFile = new File(initLogURI);
                                String logname = initLogFile.getAbsolutePath();
                                FileAppender initLogAppender = new FileAppender(initLayout,logname);
+                               initLogAppender.setName("SPInitLogFileAppender");
                                initLogger.addAppender(initLogAppender);
-                               initLogger.setLevel(Level.DEBUG);
+                               initLogger2.addAppender(initLogAppender);
                        } catch (URISyntaxException e1) {
                                servletContext.log("InitializationLog context parameter is not a valid URL", e1);
                        } catch (IOException e1) {
@@ -92,7 +111,12 @@ public class ContextListener implements ServletContextListener {
                        
                
                samlLogger.addAppender(threadAppender);
-               samlLogger.setLevel(Level.DEBUG);
+               samlLogger.addAppender(consoleAppender);
+               samlLogger.setLevel(defaultLogLevel);
+
+               serviceLogger.addAppender(consoleAppender);
+               serviceLogger.setLevel(defaultLogLevel);
+               
                
                try {
                        ServletContextInitializer.initServiceProvider(servletContext);