You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ca...@apache.org on 2007/04/13 00:19:28 UTC

svn commit: r528257 - in /logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j: AppenderSkeleton.java net/SocketAppender.java spi/LocationInfo.java spi/LoggingEvent.java spi/ThrowableInformation.java

Author: carnold
Date: Thu Apr 12 15:19:25 2007
New Revision: 528257

URL: http://svn.apache.org/viewvc?view=rev&rev=528257
Log:
Bug 42108: Add log4j 1.3 style accessors to LoggingEvent

Modified:
    logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/AppenderSkeleton.java
    logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/net/SocketAppender.java
    logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/spi/LocationInfo.java
    logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/spi/LoggingEvent.java
    logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/spi/ThrowableInformation.java

Modified: logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/AppenderSkeleton.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/AppenderSkeleton.java?view=diff&rev=528257&r1=528256&r2=528257
==============================================================================
--- logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/AppenderSkeleton.java (original)
+++ logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/AppenderSkeleton.java Thu Apr 12 15:19:25 2007
@@ -64,6 +64,26 @@
    */
   protected boolean closed = false;
 
+    /**
+     * Create new instance.
+     */
+    public AppenderSkeleton() {
+        super();
+    }
+
+    /**
+     * Create new instance.
+     * Provided for compatibility with log4j 1.3.
+     *
+     * @param isActive true if appender is ready for use upon construction.
+     *                 Not used in log4j 1.2.x.
+     * @since 1.2.15
+     */
+    protected AppenderSkeleton(final boolean isActive) {
+        super();
+    }
+
+
 
   /**
      Derived appenders should override this method if option structure

Modified: logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/net/SocketAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/net/SocketAppender.java?view=diff&rev=528257&r1=528256&r2=528257
==============================================================================
--- logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/net/SocketAppender.java (original)
+++ logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/net/SocketAppender.java Thu Apr 12 15:19:25 2007
@@ -102,8 +102,9 @@
 
   /**
      The default port number of remote logging server (4560).
+     @since 1.2.15
   */
-  static final int DEFAULT_PORT                 = 4560;
+  static public final int DEFAULT_PORT                 = 4560;
 
   /**
      The default reconnection delay (30000 milliseconds or 30 seconds).

Modified: logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/spi/LocationInfo.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/spi/LocationInfo.java?view=diff&rev=528257&r1=528256&r2=528257
==============================================================================
--- logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/spi/LocationInfo.java (original)
+++ logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/spi/LocationInfo.java Thu Apr 12 15:19:25 2007
@@ -64,6 +64,14 @@
 
   static final long serialVersionUID = -1325822038990805636L;
 
+    /**
+     * NA_LOCATION_INFO is provided for compatibility with log4j 1.3.
+     * @since 1.2.15
+     */
+    public static final LocationInfo NA_LOCATION_INFO =
+            new LocationInfo(NA, NA, NA, NA);
+
+
 
   // Check if we are running in IBM's visual age.
   static boolean inVisualAge = false;
@@ -144,6 +152,25 @@
       }
       // everything between is the requested stack item
       this.fullInfo = s.substring(ibegin, iend);
+    }
+
+
+    /**
+     * Create new instance.
+     * @param file source file name
+     * @param classname class name
+     * @param method method
+     * @param line source line number
+     */
+    public LocationInfo(
+      final String file,
+      final String classname,
+      final String method,
+      final String line) {
+      this.fileName = file;
+      this.className = classname;
+      this.methodName = method;
+      this.lineNumber = line;
     }
 
     /**

Modified: logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/spi/LoggingEvent.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/spi/LoggingEvent.java?view=diff&rev=528257&r1=528256&r2=528257
==============================================================================
--- logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/spi/LoggingEvent.java (original)
+++ logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/spi/LoggingEvent.java Thu Apr 12 15:19:25 2007
@@ -25,6 +25,10 @@
 import java.io.ObjectOutputStream;
 import java.io.ObjectInputStream;
 import java.util.Hashtable;
+import java.util.Set;
+import java.util.Collections;
+import java.util.Map;
+import java.util.HashMap;
 
 // Contributors:   Nelson Minar <ne...@monkey.org>
 //                 Wolf Siberski
@@ -183,6 +187,56 @@
     this.timeStamp = timeStamp;
   }
 
+    /**
+       Create new instance.
+       @since 1.2.15
+       @param fqnOfCategoryClass Fully qualified class name
+                 of Logger implementation.
+       @param logger The logger generating this event.
+       @param timeStamp the timestamp of this logging event
+       @param level The level of this event.
+       @param message  The message of this event.
+       @param threadName thread name
+       @param throwable The throwable of this event.
+       @param ndc Nested diagnostic context
+       @param info Location info
+       @param properties MDC properties
+     */
+    public LoggingEvent(final String fqnOfCategoryClass,
+                        final Logger logger,
+                        final long timeStamp,
+                        final Level level,
+                        final Object message,
+                        final String threadName,
+                        final ThrowableInformation throwable,
+                        final String ndc,
+                        final LocationInfo info,
+                        final java.util.Map properties) {
+      super();
+      this.fqnOfCategoryClass = fqnOfCategoryClass;
+      this.logger = logger;
+      if (logger != null) {
+          categoryName = logger.getName();
+      } else {
+          categoryName = null;
+      }
+      this.level = level;
+      this.message = message;
+      if(throwable != null) {
+        this.throwableInfo = throwable;
+      }
+
+      this.timeStamp = timeStamp;
+      this.threadName = threadName;
+      ndcLookupRequired = false;
+      this.ndc = ndc;
+      this.locationInfo = info;
+      mdcCopyLookupRequired = false;
+      if (properties != null) {
+        mdcCopy = new java.util.Hashtable(properties);
+      }
+    }
+
   /**
      Set the location information for this logging event. The collected
      information is cached for future use.
@@ -426,5 +480,115 @@
       oos.writeObject(clazz.getName());
     }
   }
+
+    /**
+     * Set value for MDC property.
+     * This adds the specified MDC property to the event.
+     * Access to the MDC is not synchronized, so this
+     * method should only be called when it is known that
+     * no other threads are accessing the MDC.
+     * @since 1.2.15
+     * @param propName
+     * @param propValue
+     */
+  public final void setProperty(final String propName,
+                          final String propValue) {
+        if (mdcCopy == null) {
+            getMDCCopy();
+        }
+        if (mdcCopy == null) {
+            mdcCopy = new Hashtable();
+        }
+        mdcCopy.put(propName, propValue);      
+  }
+
+    /**
+     * Return a property for this event. The return value can be null.
+     *
+     * Equivalent to getMDC(String) in log4j 1.2.  Provided
+     * for compatibility with log4j 1.3.
+     *
+     * @param key property name
+     * @return property value or null if property not set
+     * @since 1.2.15
+     */
+    public final String getProperty(final String key) {
+        Object value = getMDC(key);
+        String retval = null;
+        if (value != null) {
+            retval = value.toString();
+        }
+        return retval;
+    }
+
+    /**
+     * Check for the existence of location information without creating it
+     * (a byproduct of calling getLocationInformation).
+     * @return true if location information has been extracted.
+     * @since 1.2.15
+     */
+    public final boolean locationInformationExists() {
+      return (locationInfo != null);
+    }
+
+    /**
+     * Getter for the event's time stamp. The time stamp is calculated starting
+     * from 1970-01-01 GMT.
+     * @return timestamp
+     *
+     * @since 1.2.15
+     */
+    public final long getTimeStamp() {
+      return timeStamp;
+    }
+
+    /**
+     * Returns the set of the key values in the properties
+     * for the event.
+     *
+     * The returned set is unmodifiable by the caller.
+     *
+     * Provided for compatibility with log4j 1.3
+     *
+     * @return Set an unmodifiable set of the property keys.
+     * @since 1.2.15
+     */
+    public Set getPropertyKeySet() {
+      return getProperties().keySet();
+    }
+
+    /**
+     * Returns the set of properties
+     * for the event.
+     *
+     * The returned set is unmodifiable by the caller.
+     *
+     * Provided for compatibility with log4j 1.3
+     *
+     * @return Set an unmodifiable map of the properties.
+     * @since 1.2.15
+     */
+    public Map getProperties() {
+      getMDCCopy();
+      Map properties;
+      if (mdcCopy == null) {
+         properties = new HashMap();
+      } else {
+         properties = mdcCopy;
+      }
+      return Collections.unmodifiableMap(properties);
+    }
+
+    /**
+     * Get the fully qualified name of the calling logger sub-class/wrapper.
+     * Provided for compatibility with log4j 1.3
+     * @return fully qualified class name, may be null.
+     * @since 1.2.15
+     */
+    public String getFQNOfLoggerClass() {
+      return fqnOfCategoryClass;
+    }
+
+
 
 }

Modified: logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/spi/ThrowableInformation.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/spi/ThrowableInformation.java?view=diff&rev=528257&r1=528256&r2=528257
==============================================================================
--- logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/spi/ThrowableInformation.java (original)
+++ logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/spi/ThrowableInformation.java Thu Apr 12 15:19:25 2007
@@ -49,6 +49,18 @@
     this.throwable = throwable;
   }
 
+    /**
+     * Create new instance.
+     * @since 1.2.15
+     * @param r String representation of throwable.
+     */
+  public ThrowableInformation(final String[] r) {
+      if (r != null) {
+        rep = (String[]) r.clone();
+      }
+  }
+
+
   public
   Throwable getThrowable() {
     return throwable;



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org