logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1505248 - in /logging/log4j/log4j2/trunk: slf4j-impl/ slf4j-impl/src/main/java/org/slf4j/helpers/ slf4j-impl/src/main/java/org/slf4j/impl/ slf4j-impl/src/test/java/org/apache/logging/slf4j/ src/changes/
Date Sun, 21 Jul 2013 00:51:34 GMT
Author: rgoers
Date: Sun Jul 21 00:51:33 2013
New Revision: 1505248

URL: http://svn.apache.org/r1505248
Log:
LOG4J2-165 - The slf4j-ext jar is now an optional dependency of the SLF4J bridge.

Added:
    logging/log4j/log4j2/trunk/slf4j-impl/src/main/java/org/slf4j/helpers/EventDataConverter.java
    logging/log4j/log4j2/trunk/slf4j-impl/src/test/java/org/apache/logging/slf4j/OptionalTest.java
      - copied, changed from r1505229, logging/log4j/log4j2/trunk/slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java
Modified:
    logging/log4j/log4j2/trunk/slf4j-impl/pom.xml
    logging/log4j/log4j2/trunk/slf4j-impl/src/main/java/org/slf4j/impl/SLF4JLogger.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/slf4j-impl/pom.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/slf4j-impl/pom.xml?rev=1505248&r1=1505247&r2=1505248&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/slf4j-impl/pom.xml (original)
+++ logging/log4j/log4j2/trunk/slf4j-impl/pom.xml Sun Jul 21 00:51:33 2013
@@ -40,6 +40,7 @@
     <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-ext</artifactId>
+      <optional>true</optional>
     </dependency>
     <dependency>
       <groupId>org.apache.logging.log4j</groupId>
@@ -62,6 +63,55 @@
       <scope>test</scope>
     </dependency>
   </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <excludes>
+            <exclude>**/*Test.java</exclude>
+          </excludes>
+        </configuration>
+        <executions>
+          <execution>
+            <id>default-tests</id>
+            <phase>test</phase>
+            <goals>
+              <goal>test</goal>
+            </goals>
+            <configuration>
+              <includes>
+                <include>**/*Test.java</include>
+              </includes>
+              <excludes>
+                <exclude>**/OptionalTest.java</exclude>
+              </excludes>
+            </configuration>
+          </execution>
+          <execution>
+            <id>test-optional</id>
+            <phase>test</phase>
+            <goals>
+              <goal>test</goal>
+            </goals>
+            <configuration>
+              <excludes>
+                <exclude>**/LoggerTest.java</exclude>
+                <exclude>**/MarkerTest.java</exclude>
+              </excludes>
+              <includes>
+                <include>**/OptionalTest.java</include>
+              </includes>
+              <classpathDependencyExcludes>
+                <classpathDependencyExcludes>org.slf4j:slf4j-ext</classpathDependencyExcludes>
+              </classpathDependencyExcludes>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
   <reporting>
     <plugins>
       <plugin>

Added: logging/log4j/log4j2/trunk/slf4j-impl/src/main/java/org/slf4j/helpers/EventDataConverter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/slf4j-impl/src/main/java/org/slf4j/helpers/EventDataConverter.java?rev=1505248&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/slf4j-impl/src/main/java/org/slf4j/helpers/EventDataConverter.java
(added)
+++ logging/log4j/log4j2/trunk/slf4j-impl/src/main/java/org/slf4j/helpers/EventDataConverter.java
Sun Jul 21 00:51:33 2013
@@ -0,0 +1,34 @@
+package org.slf4j.helpers;
+
+import org.apache.logging.log4j.message.Message;
+import org.apache.logging.log4j.message.ParameterizedMessage;
+import org.apache.logging.log4j.message.StructuredDataMessage;
+import org.slf4j.ext.EventData;
+
+import java.util.Map;
+
+/**
+ *
+ */
+public class EventDataConverter {
+
+    public Message convertEvent(final String s1, final Object[] objects, final Throwable
throwable) {
+        Message msg;
+        try {
+            final EventData data = (objects != null && objects[0] instanceof EventData)
? (EventData) objects[0] :
+                new EventData(s1);
+            msg = new StructuredDataMessage(data.getEventId(), data.getMessage(), data.getEventType());
+            for (final Map.Entry entry : data.getEventMap().entrySet()) {
+                final String key = entry.getKey().toString();
+                if (EventData.EVENT_TYPE.equals(key) || EventData.EVENT_ID.equals(key) ||
+                    EventData.EVENT_MESSAGE.equals(key)) {
+                    continue;
+                }
+                ((StructuredDataMessage) msg).put(entry.getKey().toString(), entry.getValue().toString());
+            }
+        } catch (final Exception ex) {
+            msg = new ParameterizedMessage(s1, objects, throwable);
+        }
+        return msg;
+    }
+}

Modified: logging/log4j/log4j2/trunk/slf4j-impl/src/main/java/org/slf4j/impl/SLF4JLogger.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/slf4j-impl/src/main/java/org/slf4j/impl/SLF4JLogger.java?rev=1505248&r1=1505247&r2=1505248&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/slf4j-impl/src/main/java/org/slf4j/impl/SLF4JLogger.java (original)
+++ logging/log4j/log4j2/trunk/slf4j-impl/src/main/java/org/slf4j/impl/SLF4JLogger.java Sun
Jul 21 00:51:33 2013
@@ -16,18 +16,15 @@
  */
 package org.slf4j.impl;
 
-import java.util.Map;
-
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.ParameterizedMessage;
 import org.apache.logging.log4j.message.SimpleMessage;
-import org.apache.logging.log4j.message.StructuredDataMessage;
 import org.apache.logging.log4j.spi.AbstractLogger;
 import org.apache.logging.log4j.spi.AbstractLoggerWrapper;
 import org.slf4j.Marker;
 import org.slf4j.MarkerFactory;
-import org.slf4j.ext.EventData;
+import org.slf4j.helpers.EventDataConverter;
 import org.slf4j.spi.LocationAwareLogger;
 
 /**
@@ -40,11 +37,13 @@ public class SLF4JLogger implements Loca
     private final boolean eventLogger;
     private final AbstractLoggerWrapper logger;
     private final String name;
+    private final EventDataConverter converter;
 
     public SLF4JLogger(final AbstractLogger logger, final String name) {
         this.logger = new AbstractLoggerWrapper(logger, name, null);
         eventLogger = "EventLogger".equals(name);
         this.name = name;
+        this.converter = createConverter();
     }
 
     @Override
@@ -485,23 +484,8 @@ public class SLF4JLogger implements Loca
             return;
         }
         Message msg;
-        if (eventLogger && marker != null && marker.contains(EVENT_MARKER))
{
-            try {
-                final EventData data = (objects != null && objects[0] instanceof
EventData) ? (EventData) objects[0] :
-                    new EventData(s1);
-                msg = new StructuredDataMessage(data.getEventId(), data.getMessage(), data.getEventType());
-                for (final Map.Entry entry : data.getEventMap().entrySet()) {
-                    final String key = entry.getKey().toString();
-                    if (EventData.EVENT_TYPE.equals(key) || EventData.EVENT_ID.equals(key)
||
-                        EventData.EVENT_MESSAGE.equals(key)) {
-                        continue;
-                    }
-                    ((StructuredDataMessage) msg).put(entry.getKey().toString(), entry.getValue().toString());
-                }
-            } catch (final Exception ex) {
-                msg = new ParameterizedMessage(s1, objects, throwable);
-            }
-
+        if (eventLogger && marker != null && marker.contains(EVENT_MARKER)
&& converter != null) {
+            msg = converter.convertEvent(s1, objects, throwable);
        } else if (objects == null) {
             msg = new SimpleMessage(s1);
         } else {
@@ -518,6 +502,15 @@ public class SLF4JLogger implements Loca
         return name;
     }
 
+    private EventDataConverter createConverter() {
+        try {
+            Class<?> clazz = Class.forName("org.slf4j.ext.EventData");
+            return new EventDataConverter();
+        } catch (ClassNotFoundException cnfe) {
+            return null;
+        }
+    }
+
     private Level getLevel(final int i) {
 
         switch (i) {

Copied: logging/log4j/log4j2/trunk/slf4j-impl/src/test/java/org/apache/logging/slf4j/OptionalTest.java
(from r1505229, logging/log4j/log4j2/trunk/slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java)
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/slf4j-impl/src/test/java/org/apache/logging/slf4j/OptionalTest.java?p2=logging/log4j/log4j2/trunk/slf4j-impl/src/test/java/org/apache/logging/slf4j/OptionalTest.java&p1=logging/log4j/log4j2/trunk/slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java&r1=1505229&r2=1505248&rev=1505248&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java
(original)
+++ logging/log4j/log4j2/trunk/slf4j-impl/src/test/java/org/apache/logging/slf4j/OptionalTest.java
Sun Jul 21 00:51:33 2013
@@ -30,15 +30,10 @@ import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.MDC;
-import org.slf4j.ext.EventData;
-import org.slf4j.ext.EventLogger;
-import org.slf4j.ext.XLogger;
-import org.slf4j.ext.XLoggerFactory;
-import org.slf4j.impl.SLF4JLogger;
-import org.slf4j.spi.LocationAwareLogger;
+import org.slf4j.Marker;
+import org.slf4j.MarkerFactory;
 
 import java.util.List;
-import java.util.Locale;
 import java.util.Map;
 
 import static org.junit.Assert.*;
@@ -46,7 +41,7 @@ import static org.junit.Assert.*;
 /**
  *
  */
-public class LoggerTest {
+public class OptionalTest {
 
     private static final String CONFIG = "log4j-test1.xml";
     private static LoggerContext ctx;
@@ -65,106 +60,14 @@ public class LoggerTest {
         StatusLogger.getLogger().reset();
     }
 
-    Logger logger = LoggerFactory.getLogger("LoggerTest");
-    XLogger xlogger = XLoggerFactory.getXLogger("LoggerTest");
-
-    @Test
-    public void basicFlow() {
-        xlogger.entry();
-        verify("List", "o.a.l.s.LoggerTest entry MDC{}" + Constants.LINE_SEP);
-        xlogger.exit();
-        verify("List", "o.a.l.s.LoggerTest exit MDC{}" + Constants.LINE_SEP);
-    }
-
-    @Test
-    public void simpleFlow() {
-        xlogger.entry(CONFIG);
-        verify("List", "o.a.l.s.LoggerTest entry with (log4j-test1.xml) MDC{}" + Constants.LINE_SEP);
-        xlogger.exit(0);
-        verify("List", "o.a.l.s.LoggerTest exit with (0) MDC{}" + Constants.LINE_SEP);
-    }
-
-    @Test
-    public void throwing() {
-        xlogger.throwing(new IllegalArgumentException("Test Exception"));
-        verify("List", "o.a.l.s.LoggerTest throwing MDC{}" + Constants.LINE_SEP);
-    }
-
-    @Test
-    public void catching() {
-        try {
-            throw new NullPointerException();
-        } catch (final Exception e) {
-            xlogger.catching(e);
-            verify("List", "o.a.l.s.LoggerTest catching MDC{}" + Constants.LINE_SEP);
-        }
-    }
-
-    @Test
-    public void debug() {
-        logger.debug("Debug message");
-        verify("List", "o.a.l.s.LoggerTest Debug message MDC{}" + Constants.LINE_SEP);
-    }
-
-    @Test
-    public void debugNoParms() {
-        logger.debug("Debug message {}");
-        verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Constants.LINE_SEP);
-        logger.debug("Debug message {}", (Object[]) null);
-        verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Constants.LINE_SEP);
-        ((LocationAwareLogger)logger).log(null, SLF4JLogger.class.getName(), LocationAwareLogger.DEBUG_INT,
-            "Debug message {}", null, null);
-        verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Constants.LINE_SEP);
-    }
-
-
-    @Test
-    public void debugWithParms() {
-        logger.debug("Hello, {}", "World");
-        verify("List", "o.a.l.s.LoggerTest Hello, World MDC{}" + Constants.LINE_SEP);
-    }
-
-    @Test
-    public void mdc() {
-
-        MDC.put("TestYear", "2010");
-        logger.debug("Debug message");
-        verify("List", "o.a.l.s.LoggerTest Debug message MDC{TestYear=2010}" + Constants.LINE_SEP);
-        MDC.clear();
-        logger.debug("Debug message");
-        verify("List", "o.a.l.s.LoggerTest Debug message MDC{}" + Constants.LINE_SEP);
-    }
-
-    @Test
-    public void testRootLogger() {
-        final Logger l = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
-        assertNotNull("No Root Logger", l);
-        assertEquals(Logger.ROOT_LOGGER_NAME, l.getName());
-    }
-
-    @Test
-    public void doubleSubst() {
-        logger.debug("Hello, {}", "Log4j {}");
-        verify("List", "o.a.l.s.LoggerTest Hello, Log4j {} MDC{}" + Constants.LINE_SEP);
-        xlogger.debug("Hello, {}", "Log4j {}");
-        verify("List", "o.a.l.s.LoggerTest Hello, Log4j Log4j {} MDC{}" + Constants.LINE_SEP);
-    }
+    Logger logger = LoggerFactory.getLogger("EventLogger");
+    Marker marker = MarkerFactory.getMarker("EVENT");
 
     @Test
     public void testEventLogger() {
-        MDC.put("loginId", "JohnDoe");
-        MDC.put("ipAddress", "192.168.0.120");
-        MDC.put("locale", Locale.US.getDisplayName());
-        final EventData data = new EventData();
-        data.setEventType("Transfer");
-        data.setEventId("Audit@18060");
-        data.setMessage("Transfer Complete");
-        data.put("ToAccount", "123456");
-        data.put("FromAccount", "123457");
-        data.put("Amount", "200.00");
-        EventLogger.logEvent(data);
+        logger.info(marker, "This is a test");
         MDC.clear();
-        verify("EventLogger", "o.a.l.s.LoggerTest Transfer [Audit@18060 Amount=\"200.00\"
FromAccount=\"123457\" ToAccount=\"123456\"] Transfer Complete" + Constants.LINE_SEP);
+        verify("EventLogger", "o.a.l.s.OptionalTest This is a test" + Constants.LINE_SEP);
     }
 
     @SuppressWarnings("unchecked")

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1505248&r1=1505247&r2=1505248&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sun Jul 21 00:51:33 2013
@@ -21,6 +21,9 @@
   </properties>
   <body>
     <release version="2.0-beta9" date="soon, very soon" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-165" dev="rgoers" type="fix">
+        The slf4j-ext jar is now an optional dependency of the SLF4J bridge.
+      </action>
       <action issue="LOG4J2-318" dev="rgoers" type="update">
         Allow shutdown hook to be disabled in the configuration.
       </action>



Mime
View raw message