changeset 24:ec56ef8f3e58

Configurable logging integrated in the Web-Application gnv/trunk@120 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Thu, 24 Sep 2009 08:18:34 +0000
parents b11f941f7eb2
children 13ba9f6e87a2
files gnv/Changelog gnv/src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java gnv/src/main/java/de/intevation/gnv/servlet/GNVActionServlet.java gnv/src/main/webapp/WEB-INF/config/log4j.properties gnv/src/main/webapp/WEB-INF/web.xml
diffstat 5 files changed, 41 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/gnv/Changelog	Wed Sep 23 15:29:26 2009 +0000
+++ b/gnv/Changelog	Thu Sep 24 08:18:34 2009 +0000
@@ -1,3 +1,13 @@
+2009-09-24  Tim Englich  <tim.englich@intevation.de>
+
+    * src/main/webapp/WEB-INF/config/log4j.properties Added:
+      Standard Log4J-properties-File which will log all Informations to the Console. 
+    * src/main/webapp/WEB-INF/web.xml Edited:
+      Added init-Parameter to tell the Application where the Log4J-propertiesfile ist located. 
+    * src/main/java/de/intevation/gnv/servlet/GNVActionServlet.java (init) Edited:
+      Reading Logging-Properties from Propertiesfile. Path maust beconfigured in the web.xml File
+
+
 2009-09-23  Tim Englich  <tim.englich@intevation.de>
 
     * src/main/webapp/WEB-INF/web.xml Edited:
--- a/gnv/src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java	Wed Sep 23 15:29:26 2009 +0000
+++ b/gnv/src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java	Thu Sep 24 08:18:34 2009 +0000
@@ -50,6 +50,7 @@
     public ActionForward execute(ActionMapping mapping, ActionForm form,
             HttpServletRequest request, HttpServletResponse response)
             throws Exception {
+        log.debug("NextArtifactStepAction.execute");
         SessionModel sm = SessionModelFactory.getInstance().getSessionModel(request);
         ArtifactDescription ad = (ArtifactDescription)sm.getCurrentArtifact();
         Collection<String> inputParameter = ad.getInputParameter();
--- a/gnv/src/main/java/de/intevation/gnv/servlet/GNVActionServlet.java	Wed Sep 23 15:29:26 2009 +0000
+++ b/gnv/src/main/java/de/intevation/gnv/servlet/GNVActionServlet.java	Thu Sep 24 08:18:34 2009 +0000
@@ -8,6 +8,7 @@
 
 import org.apache.log4j.BasicConfigurator;
 import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
 import org.apache.struts.action.ActionServlet;
 
 import de.intevation.gnv.propertiesreader.PropertiesReaderFactory;
@@ -22,12 +23,14 @@
      * the logger, used to log exceptions and additonaly information
      */
     private static Logger log = null;
-    
+
     static {
-        BasicConfigurator.configure();
-        log = Logger.getLogger(GNVActionServlet.class);
+        //BasicConfigurator.configure();
+        
     }
     
+    static String LOGGINIG_CONFIG_FILE_ID = "de.intevation.gnv.servlet.log4j.configuration";
+    
     /**
      * The UID of this Class
      */
@@ -38,6 +41,13 @@
      */
     public void init(ServletConfig config) throws ServletException {
         super.init(config);
+        try {
+            String path = config.getServletContext().getRealPath("/")+config.getInitParameter(LOGGINIG_CONFIG_FILE_ID);
+            PropertyConfigurator.configure(path);
+            log = Logger.getLogger(GNVActionServlet.class);
+        } catch (Exception e) {
+            log.error(e,e);
+        }
         log.info("PropertiesReader will be configured.");
         PropertiesReaderFactory.getInstance().initPropertiesReader(config);
      }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv/src/main/webapp/WEB-INF/config/log4j.properties	Thu Sep 24 08:18:34 2009 +0000
@@ -0,0 +1,13 @@
+# Set root logger level to DEBUG and its only appender to A1.
+log4j.rootLogger=DEBUG, A1
+
+# A1 is set to be a ConsoleAppender.
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+
+# A1 uses PatternLayout.
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
+
+# Abschalten des geschwätzigen Loggings in dre Klasse JspServlet
+log4j.category.org.apache.jasper.servlet.JspServlet=WARN
+log4j.category.org.apache.catalina.core.ContainerBase=WARN
\ No newline at end of file
--- a/gnv/src/main/webapp/WEB-INF/web.xml	Wed Sep 23 15:29:26 2009 +0000
+++ b/gnv/src/main/webapp/WEB-INF/web.xml	Thu Sep 24 08:18:34 2009 +0000
@@ -11,6 +11,10 @@
             <param-name>config</param-name>
             <param-value>/WEB-INF/config/struts-config.xml</param-value>
         </init-param>
+        <init-param>
+            <param-name>de.intevation.gnv.servlet.log4j.configuration</param-name>
+            <param-value>WEB-INF/config/log4j.properties</param-value>
+        </init-param>
         
         <init-param>
             <param-name>de.intevation.gnv.artifactdatabase.client.ArtifactDatabase.count</param-name>

http://dive4elements.wald.intevation.org