You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2016/01/12 23:34:16 UTC
logging-log4j2 git commit: Fix LOG4J2-1251 JUL bridge issue.
Repository: logging-log4j2
Updated Branches:
refs/heads/master 0ae9948d7 -> 424068f7e
Fix LOG4J2-1251 JUL bridge issue.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/424068f7
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/424068f7
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/424068f7
Branch: refs/heads/master
Commit: 424068f7e73e35ba2ad10e5087736bbf2dec6333
Parents: 0ae9948
Author: Matt Sicker <bo...@gmail.com>
Authored: Tue Jan 12 16:34:09 2016 -0600
Committer: Matt Sicker <bo...@gmail.com>
Committed: Tue Jan 12 16:34:09 2016 -0600
----------------------------------------------------------------------
.../org/apache/logging/log4j/jul/ApiLogger.java | 10 +++-
.../BracketInNotInterpolatedMessageTest.java | 56 ++++++++++++++++++++
src/changes/changes.xml | 3 ++
3 files changed, 67 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/424068f7/log4j-jul/src/main/java/org/apache/logging/log4j/jul/ApiLogger.java
----------------------------------------------------------------------
diff --git a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/ApiLogger.java b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/ApiLogger.java
index adac9be..92b2dff 100644
--- a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/ApiLogger.java
+++ b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/ApiLogger.java
@@ -23,6 +23,7 @@ import java.util.logging.LogRecord;
import java.util.logging.Logger;
import org.apache.logging.log4j.message.Message;
+import org.apache.logging.log4j.message.MessageFactory;
import org.apache.logging.log4j.spi.ExtendedLogger;
/**
@@ -36,7 +37,7 @@ import org.apache.logging.log4j.spi.ExtendedLogger;
* accurate!</p>
* <p>Also note that {@link #setParent(java.util.logging.Logger)} is explicitly unsupported. Parent loggers are
* determined using the syntax of the logger name; not through an arbitrary graph of loggers.</p>
- *
+ *
* @since 2.1
*/
public class ApiLogger extends Logger {
@@ -56,7 +57,11 @@ public class ApiLogger extends Logger {
return;
}
final org.apache.logging.log4j.Level level = LevelTranslator.toLevel(record.getLevel());
- final Message message = logger.getMessageFactory().newMessage(record.getMessage(), record.getParameters());
+ final Object[] parameters = record.getParameters();
+ final MessageFactory messageFactory = logger.getMessageFactory();
+ final Message message = parameters == null ?
+ messageFactory.newMessage(record.getMessage()) /* LOG4J2-1251: not formatted case */ :
+ messageFactory.newMessage(record.getMessage(), parameters);
final Throwable thrown = record.getThrown();
logger.logIfEnabled(FQCN, level, null, message, thrown);
}
@@ -94,6 +99,7 @@ public class ApiLogger extends Logger {
/**
* Unsupported operation.
+ *
* @throws UnsupportedOperationException always
*/
@Override
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/424068f7/log4j-jul/src/test/java/org/apache/logging/log4j/jul/BracketInNotInterpolatedMessageTest.java
----------------------------------------------------------------------
diff --git a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/BracketInNotInterpolatedMessageTest.java b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/BracketInNotInterpolatedMessageTest.java
new file mode 100644
index 0000000..951976b
--- /dev/null
+++ b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/BracketInNotInterpolatedMessageTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.jul;
+
+import java.util.List;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static java.util.logging.Level.INFO;
+import static org.hamcrest.Matchers.hasSize;
+import static org.junit.Assert.*;
+
+public class BracketInNotInterpolatedMessageTest {
+
+ @BeforeClass
+ public static void setUpClass() {
+ System.setProperty("java.util.logging.manager", LogManager.class.getName());
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ System.clearProperty("java.util.logging.manager");
+ }
+
+ @Test
+ public void noInterpolation() {
+ final Logger logger = Logger.getLogger("Test");
+ logger.info("{raw}");
+ logger.log(new LogRecord(INFO, "{raw}"));// should lead to the same as previous but was not the case LOG4J2-1251
+ final List<LogEvent> events = ListAppender.getListAppender("TestAppender").getEvents();
+ assertThat(events, hasSize(2));
+ assertEquals("{raw}", events.get(0).getMessage().getFormattedMessage());
+ assertEquals("{raw}", events.get(1).getMessage().getFormattedMessage());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/424068f7/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index b4e9e79..75c7710 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -76,6 +76,9 @@
<action issue="LOG4J2-1233" dev="ggregory" type="update" due-to="Bahri Gencsoy">
Misleading Value In Properties Example.
</action>
+ <action issue="LOG4J2-1251" dev="mattsicker" type="fix" due-to="Romain Manni-Bucau">
+ Fix JUL bridge issue where LogRecord.getParameters() is used when null.
+ </action>
</release>
<release version="2.5" date="2015-12-06" description="GA Release 2.5">
<action issue="LOG4J2-324" dev="rpopma" type="fix">