Author: rgoers
Date: Tue Jun  1 00:13:35 2010
New Revision: 949907

URL: http://svn.apache.org/viewvc?rev=949907&view=rev
Log:
Add support for external contexts.

Added:
    
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/LogLevel.java
    
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/javaee/
    
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/javaee/ContextListener.java
Modified:
    
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/spi/LoggerContext.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/pom.xml
    
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java

Added: 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/LogLevel.java
URL: 
http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/LogLevel.java?rev=949907&view=auto
==============================================================================
--- 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/LogLevel.java
 (added)
+++ 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/LogLevel.java
 Tue Jun  1 00:13:35 2010
@@ -0,0 +1,91 @@
+package org.apache.logging.log4j;
+
+import org.apache.logging.log4j.message.Message;
+
+/**
+ *
+ */
+public interface LogLevel {
+
+    LogLevel toLevel(String sArg);
+
+    /**
+     * Convert the string passed as argument to a level. If the
+     * conversion fails, then this method returns the value of
+     * <code>defaultLevel</code>.
+     */
+    LogLevel toLevel(String sArg, Level defaultLevel);
+
+
+    /**
+     * Log a message object with the current level
+     *
+     * @param message the message object to log.
+     */
+    void log(Logger logger, String message);
+
+    /**
+     * Log a message at the current level including the
+     * stack trace of the {...@link Throwable}<code>t</code> passed as 
parameter.
+
+     * @param message the message object to log.
+     * @param t       the exception to log, including its stack trace.
+     */
+    void log(Logger logger, String message, Throwable t);
+
+    /**
+     * Log a message object with the current level.
+     *
+     * @param message the message object to log.
+     */
+    void log(Logger logger, Object message);
+
+    /**
+     * Log a message at the current level including the
+     * stack trace of the {...@link Throwable}<code>t</code> passed as 
parameter.
+     *
+     * @param message the message object to log.
+     * @param t       the exception to log, including its stack trace.
+     */
+    void log(Logger logger, Object message, Throwable t);
+
+    /**
+     * Log a message with parameters at the current level.
+     *
+     * @param message the message to log.
+     * @param params  parameters to the message.
+     */
+    void log(Logger logger, String message, Object... params);
+
+    /**
+     * Log a message with the specific Marker at the current level.
+     *
+     * @param msg the message string to be logged
+     */
+    void log(Logger logger, Message msg);
+
+    /**
+     * Log a message with the specific Marker at the current level.
+     *
+     * @param msg the message string to be logged
+     * @param t   A Throwable or null.
+     */
+    void log(Logger logger, Message msg, Throwable t);
+
+    /**
+     * Log a message with the specific Marker at the current level.
+     *
+     * @param marker the marker data specific to this log statement
+     * @param msg    the message string to be logged
+     */
+    void log(Logger logger, Marker marker, Message msg);
+
+    /**
+     * Log a message with the specific Marker at the current level.
+     *
+     * @param marker the marker data specific to this log statement
+     * @param msg    the message string to be logged
+     * @param t      A Throwable or null.
+     */
+    void log(Logger logger, Marker marker, Message msg, Throwable t);
+}

Modified: 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/spi/LoggerContext.java
URL: 
http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/spi/LoggerContext.java?rev=949907&r1=949906&r2=949907&view=diff
==============================================================================
--- 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/spi/LoggerContext.java
 (original)
+++ 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/spi/LoggerContext.java
 Tue Jun  1 00:13:35 2010
@@ -10,4 +10,6 @@ public interface LoggerContext {
     Logger getLogger(String name);
 
     boolean hasLogger(String name);
+
+    Object getExternalContext();
 }

Modified: 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/pom.xml
URL: 
http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/pom.xml?rev=949907&r1=949906&r2=949907&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/pom.xml 
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/pom.xml 
Tue Jun  1 00:13:35 2010
@@ -41,12 +41,18 @@
       <artifactId>log4j2-api</artifactId>
       <version>1.99.0-SNAPSHOT</version>
     </dependency>
-       <dependency>
+         <dependency>
       <groupId>oro</groupId>
       <artifactId>oro</artifactId>
       <version>2.0.8</version>
       <scope>test</scope>
     </dependency>
+         <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>servlet-api</artifactId>
+      <version>2.4</version>
+      <scope>provided</scope>
+    </dependency>
   </dependencies>
 
 </project>

Modified: 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
URL: 
http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java?rev=949907&r1=949906&r2=949907&view=diff
==============================================================================
--- 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
 (original)
+++ 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
 Tue Jun  1 00:13:35 2010
@@ -38,10 +38,20 @@ public class LoggerContext implements or
 
     private static final LoggerFactory FACTORY = new Factory();
 
+    private Object externalContext = null;
+
     public LoggerContext() {
         reconfigure();
     }
 
+    public void setExternalContext(Object context) {
+        this.externalContext = context;
+    }
+
+    public Object getExternalContext() {
+        return this.externalContext;
+    }
+
     public Logger getLogger(String name) {
         return getLogger(FACTORY, name);
     }

Added: 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/javaee/ContextListener.java
URL: 
http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/javaee/ContextListener.java?rev=949907&view=auto
==============================================================================
--- 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/javaee/ContextListener.java
 (added)
+++ 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/javaee/ContextListener.java
 Tue Jun  1 00:13:35 2010
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.javaee;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.spi.LoggerContext;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+/**
+ *
+ */
+public class ContextListener implements ServletContextListener {
+
+    public void contextInitialized(ServletContextEvent servletContextEvent) {
+        ServletContext context = servletContextEvent.getServletContext();
+
+        LoggerContext ctx = LogManager.getContext();
+        if (ctx == null) {
+            context.log("Unable to initialize logging context");
+        }
+        ((org.apache.logging.log4j.core.LoggerContext) 
ctx).setExternalContext(context);
+    }
+
+    public void contextDestroyed(ServletContextEvent servletContextEvent) {
+        LoggerContext ctx = LogManager.getContext();
+        if (ctx != null) {
+            ((org.apache.logging.log4j.core.LoggerContext) 
ctx).setExternalContext(null);
+        }
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to