logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpo...@apache.org
Subject svn commit: r1555339 - in /logging/log4j/log4j2/trunk: log4j-core/src/main/java/org/apache/logging/log4j/core/async/ log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ log4j-core/src/test/java/org/apache/logging/log4j/core/async/ log4j-core/s...
Date Sat, 04 Jan 2014 11:55:19 GMT
Author: rpopma
Date: Sat Jan  4 11:55:19 2014
New Revision: 1555339

URL: http://svn.apache.org/r1555339
Log:
LOG4J-462, LOG4J-465 Log4jLogEvent constructor and RingBufferLogEvent#getLevel convert null
Level to Level.OFF to prevent NPEs.

Added:
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java
  (with props)
Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/Log4jLogEventTest.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java?rev=1555339&r1=1555338&r2=1555339&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
Sat Jan  4 11:55:19 2014
@@ -143,6 +143,9 @@ public class RingBufferLogEvent implemen
 
     @Override
     public Level getLevel() {
+        if (level == null) {
+            level = Level.OFF; // LOG4J2-462, LOG4J2-465
+        }
         return level;
     }
 

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java?rev=1555339&r1=1555338&r2=1555339&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
Sat Jan  4 11:55:19 2014
@@ -158,7 +158,7 @@ public class Log4jLogEvent implements Lo
         name = loggerName;
         this.marker = marker;
         this.fqcnOfLogger = fqcn;
-        this.level = level;
+        this.level = (level == null) ? Level.OFF : level; // LOG4J2-462, LOG4J2-465
         this.message = message;
         this.throwable = t;
         this.mdc = mdc;

Added: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java?rev=1555339&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java
(added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java
Sat Jan  4 11:55:19 2014
@@ -0,0 +1,148 @@
+/*
+ * 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.async;
+
+import static org.junit.Assert.*;
+
+import java.util.Map;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.ThreadContext.ContextStack;
+import org.apache.logging.log4j.message.Message;
+import org.apache.logging.log4j.message.TimestampMessage;
+import org.junit.Test;
+
+/**
+ * Tests the RingBufferLogEvent class.
+ */
+public class RingBufferLogEventTest {
+
+    @Test
+    public void testGetLevelReturnsOffIfNullLevelSet() {
+        RingBufferLogEvent evt = new RingBufferLogEvent();
+        String loggerName = null;
+        Marker marker = null;
+        String fqcn = null;
+        Level level = null;
+        Message data = null;
+        Throwable t = null;
+        Map<String, String> map = null;
+        ContextStack contextStack = null;
+        String threadName = null;
+        StackTraceElement location = null;
+        long currentTimeMillis = 0;
+        evt.setValues(null, loggerName, marker, fqcn, level, data, t, map,
+                contextStack, threadName, location, currentTimeMillis);
+        assertEquals(Level.OFF, evt.getLevel());
+    }
+
+    @Test
+    public void testGetMessageReturnsNonNullMessage() {
+        RingBufferLogEvent evt = new RingBufferLogEvent();
+        String loggerName = null;
+        Marker marker = null;
+        String fqcn = null;
+        Level level = null;
+        Message data = null;
+        Throwable t = null;
+        Map<String, String> map = null;
+        ContextStack contextStack = null;
+        String threadName = null;
+        StackTraceElement location = null;
+        long currentTimeMillis = 0;
+        evt.setValues(null, loggerName, marker, fqcn, level, data, t, map,
+                contextStack, threadName, location, currentTimeMillis);
+        assertNotNull(evt.getMessage());
+    }
+
+    @Test
+    public void testGetMillisReturnsConstructorMillisForNormalMessage() {
+        RingBufferLogEvent evt = new RingBufferLogEvent();
+        String loggerName = null;
+        Marker marker = null;
+        String fqcn = null;
+        Level level = null;
+        Message data = null;
+        Throwable t = null;
+        Map<String, String> map = null;
+        ContextStack contextStack = null;
+        String threadName = null;
+        StackTraceElement location = null;
+        long currentTimeMillis = 123;
+        evt.setValues(null, loggerName, marker, fqcn, level, data, t, map,
+                contextStack, threadName, location, currentTimeMillis);
+        assertEquals(123, evt.getMillis());
+    }
+
+    static class TimeMsg implements Message, TimestampMessage {
+        private static final long serialVersionUID = -2038413535672337079L;
+        private final String msg;
+        private final long timestamp;
+
+        public TimeMsg(String msg, long timestamp) {
+            this.msg = msg;
+            this.timestamp = timestamp;
+        }
+
+        @Override
+        public long getTimestamp() {
+            return timestamp;
+        }
+
+        @Override
+        public String getFormattedMessage() {
+            return msg;
+        }
+
+        @Override
+        public String getFormat() {
+            return null;
+        }
+
+        @Override
+        public Object[] getParameters() {
+            return null;
+        }
+
+        @Override
+        public Throwable getThrowable() {
+            return null;
+        }
+    }
+
+    @Test
+    public void testGetMillisReturnsMsgTimestampForTimestampMessage() {
+        RingBufferLogEvent evt = new RingBufferLogEvent();
+        String loggerName = null;
+        Marker marker = null;
+        String fqcn = null;
+        Level level = null;
+        Message data = new TimeMsg("", 567);
+        Throwable t = null;
+        Map<String, String> map = null;
+        ContextStack contextStack = null;
+        String threadName = null;
+        StackTraceElement location = null;
+        long currentTimeMillis = 123;
+        evt.setValues(null, loggerName, marker, fqcn, level, data, t, map,
+                contextStack, threadName, location, currentTimeMillis);
+        assertEquals(567, evt.getMillis());
+    }
+
+}

Propchange: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/Log4jLogEventTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/Log4jLogEventTest.java?rev=1555339&r1=1555338&r2=1555339&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/Log4jLogEventTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/Log4jLogEventTest.java
Sat Jan  4 11:55:19 2014
@@ -24,10 +24,21 @@ import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 
 import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.Marker;
 import org.apache.logging.log4j.message.SimpleMessage;
 import org.junit.Test;
 
 public class Log4jLogEventTest {
+    
+    @Test
+    public void testNullLevelReplacedWithOFF() throws Exception {
+        final Marker marker = null;
+        final Throwable t = null;
+        final Level NULL_LEVEL = null;
+        final Log4jLogEvent evt = new Log4jLogEvent("some.test", marker, "",
+                NULL_LEVEL, new SimpleMessage("abc"), t);
+        assertEquals(Level.OFF, evt.getLevel());
+    }
 
     @Test
     public void testJavaIoSerializable() throws Exception {

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1555339&r1=1555338&r2=1555339&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sat Jan  4 11:55:19 2014
@@ -21,6 +21,12 @@
   </properties>
   <body>
     <release version="2.0-RC1" date="2013-MM-DD" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-462" dev="rpopma" type="fix" due-to="Daisuke Baba">
+        Fix LogEvent to never return null Level, fixes LevelPatternConverter.format may throw
NPE.
+      </action>
+      <action issue="LOG4J2-465" dev="rpopma" type="fix" due-to="Daisuke Baba">
+        Fix LogEvent to never return null Level, fixes ThresholdFilter throws NPE.
+      </action>
       <action issue="LOG4J2-471" dev="rpopma" type="fix" due-to="Anthony Baldocchi">
         Fixed issue where toString methods that perform logging could deadlock AsyncLogger.
       </action>



Mime
View raw message