You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2005/06/30 18:30:36 UTC

svn commit: r208646 - /cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java

Author: cziegeler
Date: Thu Jun 30 09:30:33 2005
New Revision: 208646

URL: http://svn.apache.org/viewcvs?rev=208646&view=rev
Log:
Only create context if LogKit is used

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

Modified: cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java?rev=208646&r1=208645&r2=208646&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java Thu Jun 30 09:30:33 2005
@@ -96,6 +96,9 @@
     /** The time the cocoon instance was created. */
     protected long creationTime;
 
+    /** We use LogKit */
+    protected boolean isLogKit = false;
+
     /**
      * Setup a new instance.
      * @param environment The hook back to the environment.
@@ -374,19 +377,22 @@
      * TODO - Move this to the logger manager and make it LogKit independent.
      */
     public Object initializePerRequestLoggingContext(Environment env) {
-        ContextMap ctxMap;
-        // Initialize a fresh log context containing the object model: it
-        // will be used by the CocoonLogFormatter
-        ctxMap = ContextMap.getCurrentContext();
-        // Add thread name (default content for empty context)
-        String threadName = Thread.currentThread().getName();
-        ctxMap.set("threadName", threadName);
-        // Add the object model
-        ctxMap.set("objectModel", env.getObjectModel());
-        // Add a unique request id (threadName + currentTime
-        ctxMap.set("request-id", threadName + System.currentTimeMillis());
-        
-        return ctxMap;
+        if ( this.isLogKit ) {
+            ContextMap ctxMap;
+            // Initialize a fresh log context containing the object model: it
+            // will be used by the CocoonLogFormatter
+            ctxMap = ContextMap.getCurrentContext();
+            // Add thread name (default content for empty context)
+            String threadName = Thread.currentThread().getName();
+            ctxMap.set("threadName", threadName);
+            // Add the object model
+            ctxMap.set("objectModel", env.getObjectModel());
+            // Add a unique request id (threadName + currentTime
+            ctxMap.set("request-id", threadName + System.currentTimeMillis());
+            
+            return ctxMap;
+        }
+        return null;   
     }
 
     /**
@@ -568,8 +574,12 @@
         }
         try {
             Class clazz = Class.forName(loggerManagerClass);
+            if ( loggerManagerClass.equals(LogKitLoggerManager.class.getName()) ) {
+                this.isLogKit = true;
+            }
             return (LoggerManager) clazz.newInstance();
         } catch (Exception e) {
+            this.isLogKit = true;
             return new LogKitLoggerManager();
         }
     }



Re: svn commit: r208646 - /cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java

Posted by Carsten Ziegeler <cz...@apache.org>.
Ralph Goers wrote:
> I would have no problem with that if LoggerManager had a method that was 
> called at the beginning of a request.  If that was the case I wouldn't 
> even be using the Cocoon ContextMap as our LoggingFramework has its own 
> equivalent (for Log4J NDC type stuff).  This would actually simplify my 
> code.  What would the method signature look like?
> 
I'm thinking of providing an ExtendedLoggerManager interface that
extends the LoggerManager by two methods:
Object createPerRequestLoggingContext(Environment env);
void cleanupPerRequestLoggingContext(Object o)

The first method is called at the beginning of each request and can
return a handle which is used as input to the second method at the end
of each request.

WDYT?

Carsten


-- 
Carsten Ziegeler - Open Source Group, S&N AG
http://www.s-und-n.de
http://www.osoco.org/weblogs/rael/

Re: svn commit: r208646 - /cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java

Posted by Ralph Goers <Ra...@dslextreme.com>.
I would have no problem with that if LoggerManager had a method that was 
called at the beginning of a request.  If that was the case I wouldn't 
even be using the Cocoon ContextMap as our LoggingFramework has its own 
equivalent (for Log4J NDC type stuff).  This would actually simplify my 
code.  What would the method signature look like?

Ralph

Carsten Ziegeler wrote:

>And I guess you're using your own LoggerManager, right?
>In fact, this initialization is only for LogKit (or logging systems
>using LogKit classes) and I want to move this into the LoggerManager.
>Would it be ok for you, if your own LoggerManager implementation would
>set the values?
>
>Carsten
>
>  
>


Re: svn commit: r208646 - /cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java

Posted by Carsten Ziegeler <cz...@apache.org>.
Ralph Goers wrote:
> I haven't looked deeply into what has changed in trunk here, but I 
> suspect that this change will cause me problems.  My Logger 
> implementation needs to get the objectModel from the contextMap and is 
> expecting it to be there.
> 
And I guess you're using your own LoggerManager, right?
In fact, this initialization is only for LogKit (or logging systems
using LogKit classes) and I want to move this into the LoggerManager.
Would it be ok for you, if your own LoggerManager implementation would
set the values?

Carsten

-- 
Carsten Ziegeler - Open Source Group, S&N AG
http://www.s-und-n.de
http://www.osoco.org/weblogs/rael/

Re: svn commit: r208646 - /cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java

Posted by Ralph Goers <Ra...@dslextreme.com>.
I haven't looked deeply into what has changed in trunk here, but I 
suspect that this change will cause me problems.  My Logger 
implementation needs to get the objectModel from the contextMap and is 
expecting it to be there.

Ralph

cziegeler@apache.org wrote:

>Author: cziegeler
>Date: Thu Jun 30 09:30:33 2005
>New Revision: 208646
>
>URL: http://svn.apache.org/viewcvs?rev=208646&view=rev
>Log:
>Only create context if LogKit is used
>
>Modified:
>    cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java
>
>Modified: cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java
>URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java?rev=208646&r1=208645&r2=208646&view=diff
>==============================================================================
>--- cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java (original)
>+++ cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java Thu Jun 30 09:30:33 2005
>@@ -96,6 +96,9 @@
>     /** The time the cocoon instance was created. */
>     protected long creationTime;
> 
>+    /** We use LogKit */
>+    protected boolean isLogKit = false;
>+
>     /**
>      * Setup a new instance.
>      * @param environment The hook back to the environment.
>@@ -374,19 +377,22 @@
>      * TODO - Move this to the logger manager and make it LogKit independent.
>      */
>     public Object initializePerRequestLoggingContext(Environment env) {
>-        ContextMap ctxMap;
>-        // Initialize a fresh log context containing the object model: it
>-        // will be used by the CocoonLogFormatter
>-        ctxMap = ContextMap.getCurrentContext();
>-        // Add thread name (default content for empty context)
>-        String threadName = Thread.currentThread().getName();
>-        ctxMap.set("threadName", threadName);
>-        // Add the object model
>-        ctxMap.set("objectModel", env.getObjectModel());
>-        // Add a unique request id (threadName + currentTime
>-        ctxMap.set("request-id", threadName + System.currentTimeMillis());
>-        
>-        return ctxMap;
>+        if ( this.isLogKit ) {
>+            ContextMap ctxMap;
>+            // Initialize a fresh log context containing the object model: it
>+            // will be used by the CocoonLogFormatter
>+            ctxMap = ContextMap.getCurrentContext();
>+            // Add thread name (default content for empty context)
>+            String threadName = Thread.currentThread().getName();
>+            ctxMap.set("threadName", threadName);
>+            // Add the object model
>+            ctxMap.set("objectModel", env.getObjectModel());
>+            // Add a unique request id (threadName + currentTime
>+            ctxMap.set("request-id", threadName + System.currentTimeMillis());
>+            
>+            return ctxMap;
>+        }
>+        return null;   
>     }
> 
>     /**
>@@ -568,8 +574,12 @@
>         }
>         try {
>             Class clazz = Class.forName(loggerManagerClass);
>+            if ( loggerManagerClass.equals(LogKitLoggerManager.class.getName()) ) {
>+                this.isLogKit = true;
>+            }
>             return (LoggerManager) clazz.newInstance();
>         } catch (Exception e) {
>+            this.isLogKit = true;
>             return new LogKitLoggerManager();
>         }
>     }
>
>
>  
>