cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r158345 - in cocoon/trunk/src: core/java/org/apache/cocoon/core/Core.java core/java/org/apache/cocoon/core/CoreUtil.java java/org/apache/cocoon/servlet/CocoonServlet.java
Date Sun, 20 Mar 2005 19:39:31 GMT
Author: cziegeler
Date: Sun Mar 20 11:39:31 2005
New Revision: 158345

URL: http://svn.apache.org/viewcvs?view=rev&rev=158345
Log:
Add logging code

Modified:
    cocoon/trunk/src/core/java/org/apache/cocoon/core/Core.java
    cocoon/trunk/src/core/java/org/apache/cocoon/core/CoreUtil.java
    cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/Core.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/core/Core.java?view=diff&r1=158344&r2=158345
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/Core.java (original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/Core.java Sun Mar 20 11:39:31 2005
@@ -29,8 +29,10 @@
 import org.apache.avalon.framework.context.Context;
 import org.apache.avalon.framework.context.ContextException;
 import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.context.DefaultContext;
 import org.apache.cocoon.Constants;
 import org.apache.cocoon.configuration.Settings;
+import org.apache.log.LogTarget;
 
 /**
  * This is the core Cocoon component.
@@ -228,12 +230,15 @@
         InputStream getInputStream(String path);
         
         void configure(Settings settings);
-        
+        void configureLoggingContext(DefaultContext context);
+
         ClassLoader getInitClassLoader();
 
         org.apache.cocoon.environment.Context getEnvironmentContext();
         
         String getContextPath();
+        
+        LogTarget getDefaultLogTarget();
     }
     
 }

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/CoreUtil.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/core/CoreUtil.java?view=diff&r1=158344&r2=158345
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/CoreUtil.java (original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/CoreUtil.java Sun Mar 20 11:39:31 2005
@@ -20,6 +20,7 @@
 import java.lang.reflect.Constructor;
 import java.net.MalformedURLException;
 
+import org.apache.avalon.excalibur.logger.LoggerManager;
 import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.avalon.framework.context.DefaultContext;
 import org.apache.avalon.framework.logger.Logger;
@@ -45,6 +46,9 @@
     /** The settings */
     protected final Settings settings;
 
+    private Logger log;
+    private LoggerManager loggerManager;
+
     public CoreUtil(Core.BootstrapEnvironment e) 
     throws Exception {
         this.env = e;
@@ -142,16 +146,25 @@
             // we simply ignore this
         //}
 
-        // TODO create logger
-        final Logger logger = null;
+        // Init logger
+        initLogger();
+        if (this.log.isDebugEnabled()) {
+            this.log.debug(this.settings.toString());
+            this.log.debug("getRealPath for /: " + this.env.getContextPath());
+            if ( this.env.getContextPath() == null ) {                
+                this.log.debug("getResource for /WEB-INF: " + debugPathOne);
+                this.log.debug("Path for Root: " + debugPathTwo);
+            }
+        }
+
 
         // Output some debug info
-        if (logger.isDebugEnabled()) {
-            logger.debug("Context URL: " + contextURL);
+        if (this.log.isDebugEnabled()) {
+            this.log.debug("Context URL: " + contextURL);
             if (workDirParam != null) {
-                logger.debug("Using work-directory " + workDir);
+                this.log.debug("Using work-directory " + workDir);
             } else {
-                logger.debug("Using default work-directory " + workDir);
+                this.log.debug("Using default work-directory " + workDir);
             }
         }
 
@@ -171,13 +184,13 @@
                     uploadDir = new File(env.getContextPath(), uploadDirParam);
                 }
             }
-            if (logger.isDebugEnabled()) {
-                logger.debug("Using upload-directory " + uploadDir);
+            if (this.log.isDebugEnabled()) {
+                this.log.debug("Using upload-directory " + uploadDir);
             }
         } else {
             uploadDir = new File(workDir, "upload-dir" + File.separator);
-            if (logger.isDebugEnabled()) {
-                logger.debug("Using default upload-directory " + uploadDir);
+            if (this.log.isDebugEnabled()) {
+                this.log.debug("Using default upload-directory " + uploadDir);
             }
         }
         uploadDir.mkdirs();
@@ -200,8 +213,8 @@
                     cacheDir = new File(env.getContextPath(), cacheDirParam);
                 }
             }
-            if (logger.isDebugEnabled()) {
-                logger.debug("Using cache-directory " + cacheDir);
+            if (this.log.isDebugEnabled()) {
+                this.log.debug("Using cache-directory " + cacheDir);
             }
         } else {
             cacheDir = new File(workDir, "cache-dir" + File.separator);
@@ -209,8 +222,8 @@
             if (parent != null) {
                 parent.mkdirs();
             }
-            if (logger.isDebugEnabled()) {
-                logger.debug("cache-directory was not set - defaulting to " + cacheDir);
+            if (this.log.isDebugEnabled()) {
+                this.log.debug("cache-directory was not set - defaulting to " + cacheDir);
             }
         }
         cacheDir.mkdirs();
@@ -262,6 +275,24 @@
             }
         }
         return parentServiceManager;
+    }
+
+    protected void initLogger() {
+        final DefaultContext subcontext = new DefaultContext(this.appContext);
+        subcontext.put("context-work", new File(this.settings.getWorkDirectory()));
+        if (this.env.getContextPath() == null) {
+            File logSCDir = new File(this.settings.getWorkDirectory(), "log");
+            logSCDir.mkdirs();
+            subcontext.put("context-root", logSCDir.toString());
+        } else {
+            subcontext.put("context-root", this.env.getContextPath());
+        }
+        this.env.configureLoggingContext(subcontext);
+
+        // FIXME - we can move the logginghelper code into this class
+        //LoggingHelper lh = new LoggingHelper(this.settings, this.env.getDefaultLogTarget(),
subcontext);
+        //this.loggerManager = lh.getLoggerManager();
+        //this.log = lh.getLogger();
     }
 
     public static final class RootServiceManager implements ServiceManager {

Modified: cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java?view=diff&r1=158344&r2=158345
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java Sun Mar 20 11:39:31
2005
@@ -71,6 +71,7 @@
 import org.apache.cocoon.util.log.CocoonLogFormatter;
 import org.apache.commons.lang.SystemUtils;
 import org.apache.log.ContextMap;
+import org.apache.log.LogTarget;
 import org.apache.log.output.ServletOutputLogTarget;
 
 /**
@@ -116,7 +117,7 @@
     protected Cocoon cocoon;
 
     /**
-     * Holds exception happened during initialization (if any)
+     * Holds exception happened during iialization (if any)
      */
     protected Exception exception;
 
@@ -1362,6 +1363,25 @@
          */
         public String getContextPath() {
             return this.contextPath;
+        }
+        
+        
+        /**
+         * @see org.apache.cocoon.core.Core.BootstrapEnvironment#getDefaultLogTarget()
+         */
+        public LogTarget getDefaultLogTarget() {
+            final CocoonLogFormatter formatter = new CocoonLogFormatter();
+            formatter.setFormat("%7.7{priority} %{time}   [%8.8{category}] " +
+                                "(%{uri}) %{thread}/%{class:short}: %{message}\\n%{throwable}");
+            return new ServletOutputLogTarget(this.config.getServletContext(), formatter);
+            
+        }
+
+        /**
+         * @see org.apache.cocoon.core.Core.BootstrapEnvironment#configureLoggingContext(org.apache.avalon.framework.context.DefaultContext)
+         */
+        public void configureLoggingContext(DefaultContext context) {
+            context.put("servlet-context", this.config.getServletContext());
         }
     }
 



Mime
View raw message