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 2014/09/10 08:44:04 UTC
[1/6] git commit: Add LevelConverter interface to JUL bridge.
Repository: logging-log4j2
Updated Branches:
refs/heads/master 0801d8d81 -> 47cf2d8e2
Add LevelConverter interface to JUL bridge.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/dc8be985
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/dc8be985
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/dc8be985
Branch: refs/heads/master
Commit: dc8be9853e0ca7989b081a1091315bae6ac98ca1
Parents: 0801d8d
Author: Matt Sicker <ma...@apache.org>
Authored: Wed Sep 10 01:39:06 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Wed Sep 10 01:39:06 2014 -0500
----------------------------------------------------------------------
.../log4j/jul/DefaultLevelConverter.java | 67 ++++++++++++++++++++
.../logging/log4j/jul/LevelConverter.java | 43 +++++++++++++
2 files changed, 110 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/dc8be985/log4j-jul/src/main/java/org/apache/logging/log4j/jul/DefaultLevelConverter.java
----------------------------------------------------------------------
diff --git a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/DefaultLevelConverter.java b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/DefaultLevelConverter.java
new file mode 100644
index 0000000..71194ac
--- /dev/null
+++ b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/DefaultLevelConverter.java
@@ -0,0 +1,67 @@
+/*
+ * 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.IdentityHashMap;
+import java.util.Map;
+
+import org.apache.logging.log4j.Level;
+
+/**
+ * Default implementation of LevelConverter strategy.
+ */
+public class DefaultLevelConverter implements LevelConverter {
+
+ private final Map<java.util.logging.Level, Level> JDK_TO_LOG4J =
+ new IdentityHashMap<java.util.logging.Level, Level>();
+ private final Map<Level, java.util.logging.Level> LOG4J_TO_JDK =
+ new IdentityHashMap<Level, java.util.logging.Level>();
+
+ public DefaultLevelConverter() {
+ JDK_TO_LOG4J.put(java.util.logging.Level.OFF, Level.OFF);
+ JDK_TO_LOG4J.put(java.util.logging.Level.FINEST, LevelTranslator.FINEST);
+ JDK_TO_LOG4J.put(java.util.logging.Level.FINER, LevelTranslator.FINER);
+ JDK_TO_LOG4J.put(java.util.logging.Level.FINE, LevelTranslator.FINE);
+ JDK_TO_LOG4J.put(java.util.logging.Level.CONFIG, LevelTranslator.CONFIG);
+ JDK_TO_LOG4J.put(java.util.logging.Level.INFO, Level.INFO);
+ JDK_TO_LOG4J.put(java.util.logging.Level.WARNING, Level.WARN);
+ JDK_TO_LOG4J.put(java.util.logging.Level.SEVERE, Level.ERROR);
+ JDK_TO_LOG4J.put(java.util.logging.Level.ALL, Level.ALL);
+ LOG4J_TO_JDK.put(Level.OFF, java.util.logging.Level.OFF);
+ LOG4J_TO_JDK.put(Level.TRACE, java.util.logging.Level.FINEST);
+ LOG4J_TO_JDK.put(LevelTranslator.FINEST, java.util.logging.Level.FINEST);
+ LOG4J_TO_JDK.put(LevelTranslator.FINER, java.util.logging.Level.FINER);
+ LOG4J_TO_JDK.put(LevelTranslator.FINE, java.util.logging.Level.FINE);
+ LOG4J_TO_JDK.put(Level.DEBUG, java.util.logging.Level.FINE);
+ LOG4J_TO_JDK.put(LevelTranslator.CONFIG, java.util.logging.Level.CONFIG);
+ LOG4J_TO_JDK.put(Level.INFO, java.util.logging.Level.INFO);
+ LOG4J_TO_JDK.put(Level.WARN, java.util.logging.Level.WARNING);
+ LOG4J_TO_JDK.put(Level.ERROR, java.util.logging.Level.SEVERE);
+ LOG4J_TO_JDK.put(Level.ALL, java.util.logging.Level.ALL);
+ }
+
+ @Override
+ public Level toLevel(final java.util.logging.Level javaLevel) {
+ return JDK_TO_LOG4J.get(javaLevel);
+ }
+
+ @Override
+ public java.util.logging.Level toJavaLevel(final Level level) {
+ return LOG4J_TO_JDK.get(level);
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/dc8be985/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelConverter.java
----------------------------------------------------------------------
diff --git a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelConverter.java b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelConverter.java
new file mode 100644
index 0000000..36d03fa
--- /dev/null
+++ b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelConverter.java
@@ -0,0 +1,43 @@
+/*
+ * 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 org.apache.logging.log4j.Level;
+
+/**
+ * Strategy interface to convert between custom Log4j {@link Level Levels} and JUL
+ * {@link java.util.logging.Level Levels}.
+ */
+public interface LevelConverter {
+
+ /**
+ * Converts a JDK logging Level to a Log4j logging Level.
+ *
+ * @param javaLevel JDK Level to convert.
+ * @return converted Level or {@code null} if the given level could not be converted.
+ */
+ Level toLevel(java.util.logging.Level javaLevel);
+
+ /**
+ * Converts a Log4j logging Level to a JDK logging Level.
+ *
+ * @param level Log4j Level to convert.
+ * @return converted Level or {@code null} if the given level could not be converted.
+ */
+ java.util.logging.Level toJavaLevel(Level level);
+}
[4/6] git commit: Refactor tests and update a few.
Posted by ma...@apache.org.
Refactor tests and update a few.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/2d1c0f87
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/2d1c0f87
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/2d1c0f87
Branch: refs/heads/master
Commit: 2d1c0f87b11c06adedeed2039279e2574045e060
Parents: 0a7e3a4
Author: Matt Sicker <ma...@apache.org>
Authored: Wed Sep 10 01:41:43 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Wed Sep 10 01:41:43 2014 -0500
----------------------------------------------------------------------
.../logging/log4j/jul/AbstractLoggerTest.java | 104 ++++++++++++++++
.../apache/logging/log4j/jul/ApiLoggerTest.java | 78 +-----------
.../logging/log4j/jul/CoreLoggerTest.java | 118 ++++++-------------
3 files changed, 141 insertions(+), 159 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2d1c0f87/log4j-jul/src/test/java/org/apache/logging/log4j/jul/AbstractLoggerTest.java
----------------------------------------------------------------------
diff --git a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/AbstractLoggerTest.java b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/AbstractLoggerTest.java
new file mode 100644
index 0000000..c940b73
--- /dev/null
+++ b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/AbstractLoggerTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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.Logger;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public abstract class AbstractLoggerTest {
+ public static final String LOGGER_NAME = "Test";
+ protected Logger logger;
+ protected ListAppender eventAppender;
+ protected ListAppender stringAppender;
+
+ @Test
+ public void testLog() throws Exception {
+ logger.info("Informative message here.");
+ final List<LogEvent> events = eventAppender.getEvents();
+ assertThat(events, hasSize(1));
+ final LogEvent event = events.get(0);
+ assertThat(event, instanceOf(Log4jLogEvent.class));
+ assertEquals(Level.INFO, event.getLevel());
+ assertEquals(LOGGER_NAME, event.getLoggerName());
+ assertEquals("Informative message here.", event.getMessage().getFormattedMessage());
+ assertEquals(ApiLogger.class.getName(), event.getLoggerFqcn());
+ }
+
+ @Test
+ public void testLogWithCallingClass() throws Exception {
+ final Logger log = Logger.getLogger("Test.CallerClass");
+ log.config("Calling from LoggerTest");
+ final List<String> messages = stringAppender.getMessages();
+ assertThat(messages, hasSize(1));
+ final String message = messages.get(0);
+ assertEquals(AbstractLoggerTest.class.getName(), message);
+ }
+
+ @Test
+ public void testLogUsingCustomLevel() throws Exception {
+ logger.config("Config level");
+ final List<LogEvent> events = eventAppender.getEvents();
+ assertThat(events, hasSize(1));
+ final LogEvent event = events.get(0);
+ assertThat(event.getLevel(), equalTo(LevelTranslator.CONFIG));
+ }
+
+ @Test
+ public void testIsLoggable() throws Exception {
+ assertThat(logger.isLoggable(java.util.logging.Level.SEVERE), equalTo(true));
+ }
+
+ @Test
+ public void testGetName() throws Exception {
+ assertThat(logger.getName(), equalTo(LOGGER_NAME));
+ }
+
+ @Test
+ public void testGlobalLoggerName() throws Exception {
+ final Logger root = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
+ assertThat(root.getName(), equalTo(Logger.GLOBAL_LOGGER_NAME));
+ }
+
+ @Test
+ public void testGlobalLogger() throws Exception {
+ final Logger root = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
+ root.info("Test info message");
+ root.config("Test info message");
+ root.fine("Test info message");
+ final List<LogEvent> events = eventAppender.getEvents();
+ assertThat(events, hasSize(3));
+ for (final LogEvent event : events) {
+ final String message = event.getMessage().getFormattedMessage();
+ assertThat(message, equalTo("Test info message"));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2d1c0f87/log4j-jul/src/test/java/org/apache/logging/log4j/jul/ApiLoggerTest.java
----------------------------------------------------------------------
diff --git a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/ApiLoggerTest.java b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/ApiLoggerTest.java
index 7fc702c..54cc13b 100644
--- a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/ApiLoggerTest.java
+++ b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/ApiLoggerTest.java
@@ -17,12 +17,8 @@
package org.apache.logging.log4j.jul;
-import java.util.List;
import java.util.logging.Logger;
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.impl.Log4jLogEvent;
import org.apache.logging.log4j.test.appender.ListAppender;
import org.junit.After;
import org.junit.Before;
@@ -30,16 +26,9 @@ import org.junit.BeforeClass;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.*;
-public class ApiLoggerTest {
-
- public static final String LOGGER_NAME = "Test";
- private Logger logger;
- private ListAppender eventAppender;
- private ListAppender stringAppender;
+public class ApiLoggerTest extends AbstractLoggerTest {
@BeforeClass
public static void setUpClass() {
@@ -62,71 +51,6 @@ public class ApiLoggerTest {
}
@Test
- public void testLog() throws Exception {
- logger.info("Informative message here.");
- final List<LogEvent> events = eventAppender.getEvents();
- assertThat(events, hasSize(1));
- final LogEvent event = events.get(0);
- assertThat(event, instanceOf(Log4jLogEvent.class));
- assertEquals(Level.INFO, event.getLevel());
- assertEquals(LOGGER_NAME, event.getLoggerName());
- assertEquals("Informative message here.", event.getMessage().getFormattedMessage());
- assertEquals(Logger.class.getName(), event.getLoggerFqcn());
- }
-
- @Test
- public void testLogWithCallingClass() throws Exception {
- final Logger log = Logger.getLogger("Test.CallerClass");
- log.config("Calling from LoggerTest");
- final List<String> messages = stringAppender.getMessages();
- assertThat(messages, hasSize(1));
- final String message = messages.get(0);
- assertEquals(getClass().getName(), message);
- }
-
- @Test
- public void testLogUsingCustomLevel() throws Exception {
- logger.log(CustomJdkLevel.TEST, "Test level");
- final List<LogEvent> events = eventAppender.getEvents();
- assertThat(events, hasSize(1));
- final LogEvent event = events.get(0);
- assertThat(event.getLevel(), equalTo(Level.INFO));
- final String levelName = event.getContextMap().get(ApiLogger.LEVEL);
- assertThat(levelName, equalTo(CustomJdkLevel.TEST.getName()));
- }
-
- @Test
- public void testIsLoggable() throws Exception {
- assertThat(logger.isLoggable(java.util.logging.Level.SEVERE), equalTo(true));
- assertThat(logger.isLoggable(CustomJdkLevel.DEFCON_1), equalTo(true));
- }
-
- @Test
- public void testGetName() throws Exception {
- assertThat(logger.getName(), equalTo(LOGGER_NAME));
- }
-
- @Test
- public void testGlobalLoggerName() throws Exception {
- final Logger root = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
- assertThat(root.getName(), equalTo(Logger.GLOBAL_LOGGER_NAME));
- }
-
- @Test
- public void testGlobalLogger() throws Exception {
- final Logger root = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
- root.info("Test info message");
- root.config("Test info message");
- root.log(CustomJdkLevel.TEST, "Test info message");
- final List<LogEvent> events = eventAppender.getEvents();
- assertThat(events, hasSize(3));
- for (final LogEvent event : events) {
- final String message = event.getMessage().getFormattedMessage();
- assertThat(message, equalTo("Test info message"));
- }
- }
-
- @Test
public void testGetParent() throws Exception {
final Logger parent = logger.getParent();
assertNull("No parent logger should be automatically set up using log4j-api", parent);
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2d1c0f87/log4j-jul/src/test/java/org/apache/logging/log4j/jul/CoreLoggerTest.java
----------------------------------------------------------------------
diff --git a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/CoreLoggerTest.java b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/CoreLoggerTest.java
index f92f08a..abcc991 100644
--- a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/CoreLoggerTest.java
+++ b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/CoreLoggerTest.java
@@ -1,11 +1,25 @@
+/*
+ * 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.Level;
import java.util.logging.Logger;
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.impl.Log4jLogEvent;
import org.apache.logging.log4j.test.appender.ListAppender;
import org.junit.After;
import org.junit.Before;
@@ -13,16 +27,9 @@ import org.junit.BeforeClass;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.*;
-public class CoreLoggerTest {
-
- public static final String LOGGER_NAME = "Test";
- private Logger logger;
- private ListAppender eventAppender;
- private ListAppender stringAppender;
+public class CoreLoggerTest extends AbstractLoggerTest {
@BeforeClass
public static void setUpClass() {
@@ -32,85 +39,32 @@ public class CoreLoggerTest {
@Before
public void setUp() throws Exception {
logger = Logger.getLogger(LOGGER_NAME);
- assertThat(logger.getLevel(), equalTo(java.util.logging.Level.FINE));
+ assertThat(logger.getLevel(), equalTo(Level.FINE));
eventAppender = ListAppender.getListAppender("TestAppender");
stringAppender = ListAppender.getListAppender("StringAppender");
}
@After
public void tearDown() throws Exception {
- eventAppender.clear();
- stringAppender.clear();
- }
-
- @Test
- public void testLog() throws Exception {
- logger.info("Informative message here.");
- final List<LogEvent> events = eventAppender.getEvents();
- assertThat(events, hasSize(1));
- final LogEvent event = events.get(0);
- assertThat(event, instanceOf(Log4jLogEvent.class));
- assertEquals(Level.INFO, event.getLevel());
- assertEquals(LOGGER_NAME, event.getLoggerName());
- assertEquals("Informative message here.", event.getMessage().getFormattedMessage());
- assertEquals(Logger.class.getName(), event.getLoggerFqcn());
- }
-
- @Test
- public void testLogWithCallingClass() throws Exception {
- final Logger log = Logger.getLogger("Test.CallerClass");
- log.config("Calling from LoggerTest");
- final List<String> messages = stringAppender.getMessages();
- assertThat(messages, hasSize(1));
- final String message = messages.get(0);
- assertEquals(getClass().getName(), message);
- }
-
- @Test
- public void testLogUsingCustomLevel() throws Exception {
- logger.log(CustomJdkLevel.TEST, "Test level");
- final List<LogEvent> events = eventAppender.getEvents();
- assertThat(events, hasSize(1));
- final LogEvent event = events.get(0);
- assertThat(event.getLevel(), equalTo(Level.INFO));
- final String levelName = event.getContextMap().get(ApiLogger.LEVEL);
- assertThat(levelName, equalTo(CustomJdkLevel.TEST.getName()));
+ if (eventAppender != null) {
+ eventAppender.clear();
+ }
+ if (stringAppender != null) {
+ stringAppender.clear();
+ }
}
@Test
public void testSetLevel() throws Exception {
- logger.setLevel(java.util.logging.Level.SEVERE);
- assertThat(logger.getLevel(), equalTo(java.util.logging.Level.SEVERE));
- }
-
- @Test
- public void testIsLoggable() throws Exception {
- assertThat(logger.isLoggable(java.util.logging.Level.SEVERE), equalTo(true));
- assertThat(logger.isLoggable(CustomJdkLevel.DEFCON_1), equalTo(true));
- }
-
- @Test
- public void testGetName() throws Exception {
- assertThat(logger.getName(), equalTo(LOGGER_NAME));
- }
-
- @Test
- public void testGlobalLoggerName() throws Exception {
- final Logger root = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
- assertThat(root.getName(), equalTo(Logger.GLOBAL_LOGGER_NAME));
- }
-
- @Test
- public void testGlobalLogger() throws Exception {
- final Logger root = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
- root.info("Test info message");
- root.config("Test info message");
- root.log(CustomJdkLevel.TEST, "Test info message");
- final List<LogEvent> events = eventAppender.getEvents();
- assertThat(events, hasSize(3));
- for (final LogEvent event : events) {
- final String message = event.getMessage().getFormattedMessage();
- assertThat(message, equalTo("Test info message"));
- }
+ final Logger childLogger = Logger.getLogger(LOGGER_NAME + ".Child");
+ assertThat(childLogger.getLevel(), equalTo(Level.FINE));
+ logger.setLevel(Level.SEVERE);
+ assertThat(childLogger.getLevel(), equalTo(Level.FINE));
+ assertThat(logger.getLevel(), equalTo(Level.SEVERE));
+ logger.setLevel(Level.FINER);
+ assertThat(logger.getLevel(), equalTo(Level.FINER));
+ logger.setLevel(Level.FINE);
+ assertThat(logger.getLevel(), equalTo(Level.FINE));
+ assertThat(childLogger.getLevel(), equalTo(Level.FINE));
}
}
\ No newline at end of file
[6/6] git commit: Delete unused class.
Posted by ma...@apache.org.
Delete unused class.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/47cf2d8e
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/47cf2d8e
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/47cf2d8e
Branch: refs/heads/master
Commit: 47cf2d8e2bcda5d0a366de9d672c592834823103
Parents: 6944f94
Author: Matt Sicker <ma...@apache.org>
Authored: Wed Sep 10 01:43:56 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Wed Sep 10 01:43:56 2014 -0500
----------------------------------------------------------------------
.../logging/log4j/jul/CustomJdkLevel.java | 40 --------------------
1 file changed, 40 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/47cf2d8e/log4j-jul/src/test/java/org/apache/logging/log4j/jul/CustomJdkLevel.java
----------------------------------------------------------------------
diff --git a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/CustomJdkLevel.java b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/CustomJdkLevel.java
deleted file mode 100644
index 64fd96d..0000000
--- a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/CustomJdkLevel.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.logging.Level;
-
-/**
- * Custom JUL Level for unit tests.
- */
-public class CustomJdkLevel extends Level {
-
- private static final long serialVersionUID = 4681718777617726164L;
-
- protected CustomJdkLevel(final String name, final int value) {
- super(name, value);
- }
-
- // inside CONFIG range; should map to INFO
- public static final Level TEST = new CustomJdkLevel("TEST", 600);
-
- // just 1 below Level.SEVERE; should map to ERROR
- public static final Level DEFCON_2 = new CustomJdkLevel("DEFCON_2", 999);
-
- // above Level.SEVERE; should map to FATAL
- public static final Level DEFCON_1 = new CustomJdkLevel("DEFCON_1", 10000);
-}
[3/6] git commit: Add WrapperLogger.
Posted by ma...@apache.org.
Add WrapperLogger.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/0a7e3a42
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/0a7e3a42
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/0a7e3a42
Branch: refs/heads/master
Commit: 0a7e3a42a25c6c60ff8c903963a004c1a49911b5
Parents: 07e6faa
Author: Matt Sicker <ma...@apache.org>
Authored: Wed Sep 10 01:40:29 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Wed Sep 10 01:40:29 2014 -0500
----------------------------------------------------------------------
.../apache/logging/log4j/jul/WrappedLogger.java | 75 ++++++++++++++++++++
1 file changed, 75 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0a7e3a42/log4j-jul/src/main/java/org/apache/logging/log4j/jul/WrappedLogger.java
----------------------------------------------------------------------
diff --git a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/WrappedLogger.java b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/WrappedLogger.java
new file mode 100644
index 0000000..639f00c
--- /dev/null
+++ b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/WrappedLogger.java
@@ -0,0 +1,75 @@
+/*
+ * 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 org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.spi.ExtendedLogger;
+import org.apache.logging.log4j.spi.ExtendedLoggerWrapper;
+
+/**
+ * Wrapper class to ensure proper FQCN support in Logger calls.
+ */
+class WrappedLogger extends ExtendedLoggerWrapper {
+
+ private static final long serialVersionUID = 1L;
+ private static final String FQCN = ApiLogger.class.getName();
+
+ WrappedLogger(final ExtendedLogger logger) {
+ super(logger, logger.getName(), logger.getMessageFactory());
+ }
+
+ @Override
+ public void log(final Level level, final String message, final Throwable t) {
+ logIfEnabled(FQCN, level, null, message, t);
+ }
+
+ @Override
+ public void log(final Level level, final String message, final Object... params) {
+ logIfEnabled(FQCN, level, null, message, params);
+ }
+
+ @Override
+ public void log(final Level level, final String message) {
+ logIfEnabled(FQCN, level, null, message);
+ }
+
+ @Override
+ public void entry() {
+ entry(FQCN);
+ }
+
+ @Override
+ public void entry(final Object... params) {
+ entry(FQCN, params);
+ }
+
+ @Override
+ public void exit() {
+ exit(FQCN, null);
+ }
+
+ @Override
+ public <R> R exit(final R result) {
+ return exit(FQCN, result);
+ }
+
+ @Override
+ public <T extends Throwable> T throwing(final T t) {
+ return throwing(FQCN, Level.ERROR, t);
+ }
+}
Re: [2/6] git commit: Update LevelTranslator to use LevelConverter interface.
Posted by Matt Sicker <bo...@gmail.com>.
You have a good point. I'll remove the extraneous levels later tonight.
On 10 September 2014 18:00, Remko Popma <re...@gmail.com> wrote:
> I see. Thanks for the clarification.
> I did not understand why we need custom log4j levels FINE and FINEST, when
> these JUL levels are mapped to DEBUG and TRACE though.
>
>
> On Wed, Sep 10, 2014 at 11:29 PM, Matt Sicker <bo...@gmail.com> wrote:
>
>> I put them in the translator in case extensions wanted to use them.
>>
>>
>> On 10 September 2014 02:15, Remko Popma <re...@gmail.com> wrote:
>>
>>> Nice!
>>>
>>> Shall we move the remaining level constants to DefaultLevelConverter?
>>> Also, do we need to define custom log4j levels FINE and FINEST? I
>>> thought it might be good to remove them since these JUL levels already map
>>> to built-in log4j levels DEBUG and TRACE.
>>>
>>> Sent from my iPhone
>>>
>>> > On 2014/09/10, at 15:44, mattsicker@apache.org wrote:
>>> >
>>> > Update LevelTranslator to use LevelConverter interface.
>>> >
>>> >
>>> > Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
>>> > Commit:
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/07e6faa3
>>> > Tree:
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/07e6faa3
>>> > Diff:
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/07e6faa3
>>> >
>>> > Branch: refs/heads/master
>>> > Commit: 07e6faa32656571f18358e834e36b0a76d9917e6
>>> > Parents: dc8be98
>>> > Author: Matt Sicker <ma...@apache.org>
>>> > Authored: Wed Sep 10 01:39:57 2014 -0500
>>> > Committer: Matt Sicker <ma...@apache.org>
>>> > Committed: Wed Sep 10 01:39:57 2014 -0500
>>> >
>>> > ----------------------------------------------------------------------
>>> > .../logging/log4j/jul/LevelTranslator.java | 98
>>> ++++++--------------
>>> > .../logging/log4j/jul/LevelTranslatorTest.java | 31 ++++---
>>> > 2 files changed, 45 insertions(+), 84 deletions(-)
>>> > ----------------------------------------------------------------------
>>> >
>>> >
>>> >
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/07e6faa3/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
>>> > ----------------------------------------------------------------------
>>> > diff --git
>>> a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
>>> b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
>>> > index bc83457..8df429a 100644
>>> > ---
>>> a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
>>> > +++
>>> b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
>>> > @@ -17,10 +17,11 @@
>>> >
>>> > package org.apache.logging.log4j.jul;
>>> >
>>> > -import java.util.IdentityHashMap;
>>> > -import java.util.Map;
>>> > -
>>> > import org.apache.logging.log4j.Level;
>>> > +import org.apache.logging.log4j.Logger;
>>> > +import org.apache.logging.log4j.status.StatusLogger;
>>> > +import org.apache.logging.log4j.util.LoaderUtil;
>>> > +import org.apache.logging.log4j.util.PropertiesUtil;
>>> >
>>> > /**
>>> > * Utility class to convert between JDK Levels and Log4j 2 Levels.
>>> > @@ -29,37 +30,31 @@ import org.apache.logging.log4j.Level;
>>> > */
>>> > public final class LevelTranslator {
>>> >
>>> > - private static final int JDK_SEVERE =
>>> java.util.logging.Level.SEVERE.intValue(); // ERROR
>>> > - private static final int JDK_WARNING =
>>> java.util.logging.Level.WARNING.intValue(); // WARN
>>> > - private static final int JDK_INFO =
>>> java.util.logging.Level.INFO.intValue(); // INFO
>>> > - private static final int JDK_CONFIG =
>>> java.util.logging.Level.CONFIG.intValue(); // INFO
>>> > - private static final int JDK_FINE =
>>> java.util.logging.Level.FINE.intValue(); // DEBUG
>>> > - private static final int JDK_FINER =
>>> java.util.logging.Level.FINER.intValue(); // DEBUG
>>> > - private static final int JDK_FINEST =
>>> java.util.logging.Level.FINEST.intValue(); // TRACE
>>> > + public static final String LEVEL_CONVERTER_PROPERTY =
>>> "log4j.jul.levelConverter";
>>> > +
>>> > + public static final Level FINEST = Level.forName("FINEST",
>>> Level.TRACE.intLevel() + 100);
>>> > + public static final Level FINER = Level.forName("FINER",
>>> Level.TRACE.intLevel());
>>> > + public static final Level FINE = Level.forName("FINE",
>>> Level.DEBUG.intLevel());
>>> > + public static final Level CONFIG = Level.forName("CONFIG",
>>> Level.INFO.intLevel() + 50);
>>> >
>>> > - // standard level mappings
>>> > - private static final Map<java.util.logging.Level, Level>
>>> JDK_TO_LOG4J =
>>> > - new IdentityHashMap<java.util.logging.Level, Level>(10);
>>> > - private static final Map<Level, java.util.logging.Level>
>>> LOG4J_TO_JDK =
>>> > - new IdentityHashMap<Level, java.util.logging.Level>(10);
>>> > + private static final Logger LOGGER = StatusLogger.getLogger();
>>> > + private static final LevelConverter LEVEL_CONVERTER;
>>> >
>>> > static {
>>> > - JDK_TO_LOG4J.put(java.util.logging.Level.OFF, Level.OFF);
>>> > - JDK_TO_LOG4J.put(java.util.logging.Level.FINEST, Level.TRACE);
>>> > - JDK_TO_LOG4J.put(java.util.logging.Level.FINER, Level.DEBUG);
>>> > - JDK_TO_LOG4J.put(java.util.logging.Level.FINE, Level.DEBUG);
>>> > - JDK_TO_LOG4J.put(java.util.logging.Level.CONFIG, Level.INFO);
>>> > - JDK_TO_LOG4J.put(java.util.logging.Level.INFO, Level.INFO);
>>> > - JDK_TO_LOG4J.put(java.util.logging.Level.WARNING, Level.WARN);
>>> > - JDK_TO_LOG4J.put(java.util.logging.Level.SEVERE, Level.ERROR);
>>> > - JDK_TO_LOG4J.put(java.util.logging.Level.ALL, Level.ALL);
>>> > - LOG4J_TO_JDK.put(Level.OFF, java.util.logging.Level.OFF);
>>> > - LOG4J_TO_JDK.put(Level.TRACE, java.util.logging.Level.FINEST);
>>> > - LOG4J_TO_JDK.put(Level.DEBUG, java.util.logging.Level.FINE);
>>> > - LOG4J_TO_JDK.put(Level.INFO, java.util.logging.Level.INFO);
>>> > - LOG4J_TO_JDK.put(Level.WARN, java.util.logging.Level.WARNING);
>>> > - LOG4J_TO_JDK.put(Level.ERROR, java.util.logging.Level.SEVERE);
>>> > - LOG4J_TO_JDK.put(Level.ALL, java.util.logging.Level.ALL);
>>> > + final String levelConverterClassName =
>>> > +
>>> PropertiesUtil.getProperties().getStringProperty(LEVEL_CONVERTER_PROPERTY);
>>> > + if (levelConverterClassName != null) {
>>> > + LevelConverter levelConverter;
>>> > + try {
>>> > + levelConverter =
>>> LoaderUtil.newCheckedInstanceOf(levelConverterClassName,
>>> LevelConverter.class);
>>> > + } catch (final Exception e) {
>>> > + LOGGER.error("Could not create custom LevelConverter
>>> [{}].", levelConverterClassName, e);
>>> > + levelConverter = new DefaultLevelConverter();
>>> > + }
>>> > + LEVEL_CONVERTER = levelConverter;
>>> > + } else {
>>> > + LEVEL_CONVERTER = new DefaultLevelConverter();
>>> > + }
>>> > }
>>> >
>>> > /**
>>> > @@ -69,40 +64,7 @@ public final class LevelTranslator {
>>> > * @return converted Level.
>>> > */
>>> > public static Level toLevel(final java.util.logging.Level level) {
>>> > - final Level standardLevel = JDK_TO_LOG4J.get(level);
>>> > - if (standardLevel != null) {
>>> > - return standardLevel;
>>> > - }
>>> > - final int value = level.intValue();
>>> > - if (value == Integer.MAX_VALUE) {
>>> > - return Level.OFF;
>>> > - }
>>> > - if (value == Integer.MIN_VALUE) {
>>> > - return Level.ALL;
>>> > - }
>>> > - if (value <= JDK_FINEST) { // up to 300
>>> > - return Level.TRACE;
>>> > - }
>>> > - if (value <= JDK_FINER) { // 301 to 400
>>> > - return Level.DEBUG;
>>> > - }
>>> > - if (value <= JDK_FINE) { // 401 to 500
>>> > - return Level.DEBUG;
>>> > - }
>>> > - if (value <= JDK_CONFIG) { // 501 to 700
>>> > - return Level.INFO;
>>> > - }
>>> > - if (value <= JDK_INFO) { // 701 to 800
>>> > - return Level.INFO;
>>> > - }
>>> > - if (value <= JDK_WARNING) { // 801 to 900
>>> > - return Level.WARN;
>>> > - }
>>> > - if (value <= JDK_SEVERE) { // 901 to 1000
>>> > - return Level.ERROR;
>>> > - }
>>> > - // 1001+
>>> > - return Level.FATAL;
>>> > + return LEVEL_CONVERTER.toLevel(level);
>>> > }
>>> >
>>> > /**
>>> > @@ -112,11 +74,7 @@ public final class LevelTranslator {
>>> > * @return converted Level.
>>> > */
>>> > public static java.util.logging.Level toJavaLevel(final Level
>>> level) {
>>> > - final java.util.logging.Level standardLevel =
>>> LOG4J_TO_JDK.get(level);
>>> > - if (standardLevel != null) {
>>> > - return standardLevel;
>>> > - }
>>> > - return java.util.logging.Level.parse(level.name());
>>> > + return LEVEL_CONVERTER.toJavaLevel(level);
>>> > }
>>> >
>>> > private LevelTranslator() {
>>> >
>>> >
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/07e6faa3/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
>>> > ----------------------------------------------------------------------
>>> > diff --git
>>> a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
>>> b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
>>> > index 744e296..3ab5e92 100644
>>> > ---
>>> a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
>>> > +++
>>> b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
>>> > @@ -30,37 +30,40 @@ import static org.junit.Assert.*;
>>> > @RunWith(Parameterized.class)
>>> > public class LevelTranslatorTest {
>>> >
>>> > - private final java.util.logging.Level level;
>>> > - private final Level expectedLevel;
>>> > + private final java.util.logging.Level javaLevel;
>>> > + private final Level log4jLevel;
>>> >
>>> > - public LevelTranslatorTest(final java.util.logging.Level level,
>>> final Level expectedLevel) {
>>> > - this.level = level;
>>> > - this.expectedLevel = expectedLevel;
>>> > + public LevelTranslatorTest(final java.util.logging.Level
>>> javaLevel, final Level log4jLevel) {
>>> > + this.javaLevel = javaLevel;
>>> > + this.log4jLevel = log4jLevel;
>>> > }
>>> >
>>> > @Parameterized.Parameters
>>> > public static Collection<Object[]> data() {
>>> > return Arrays.asList(
>>> > new Object[][]{
>>> > - {CustomJdkLevel.TEST, Level.INFO},
>>> > - {CustomJdkLevel.DEFCON_2, Level.ERROR},
>>> > - {CustomJdkLevel.DEFCON_1, Level.FATAL},
>>> > {java.util.logging.Level.OFF, Level.OFF},
>>> > {java.util.logging.Level.ALL, Level.ALL},
>>> > {java.util.logging.Level.SEVERE, Level.ERROR},
>>> > {java.util.logging.Level.WARNING, Level.WARN},
>>> > {java.util.logging.Level.INFO, Level.INFO},
>>> > - {java.util.logging.Level.CONFIG, Level.INFO},
>>> > - {java.util.logging.Level.FINE, Level.DEBUG},
>>> > - {java.util.logging.Level.FINER, Level.DEBUG},
>>> > - {java.util.logging.Level.FINEST, Level.TRACE}
>>> > + {java.util.logging.Level.CONFIG,
>>> LevelTranslator.CONFIG},
>>> > + {java.util.logging.Level.FINE, LevelTranslator.FINE},
>>> > + {java.util.logging.Level.FINER,
>>> LevelTranslator.FINER},
>>> > + {java.util.logging.Level.FINEST,
>>> LevelTranslator.FINEST}
>>> > }
>>> > );
>>> > }
>>> >
>>> > @Test
>>> > public void testToLevel() throws Exception {
>>> > - final Level actualLevel = LevelTranslator.toLevel(level);
>>> > - assertEquals(expectedLevel, actualLevel);
>>> > + final Level actualLevel = LevelTranslator.toLevel(javaLevel);
>>> > + assertEquals(log4jLevel, actualLevel);
>>> > + }
>>> > +
>>> > + @Test
>>> > + public void testToJavaLevel() throws Exception {
>>> > + final java.util.logging.Level actualLevel =
>>> LevelTranslator.toJavaLevel(log4jLevel);
>>> > + assertEquals(javaLevel, actualLevel);
>>> > }
>>> > }
>>> > \ No newline at end of file
>>> >
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
>>> For additional commands, e-mail: log4j-dev-help@logging.apache.org
>>>
>>>
>>
>>
>> --
>> Matt Sicker <bo...@gmail.com>
>>
>
>
--
Matt Sicker <bo...@gmail.com>
Re: [2/6] git commit: Update LevelTranslator to use LevelConverter interface.
Posted by Remko Popma <re...@gmail.com>.
I see. Thanks for the clarification.
I did not understand why we need custom log4j levels FINE and FINEST, when
these JUL levels are mapped to DEBUG and TRACE though.
On Wed, Sep 10, 2014 at 11:29 PM, Matt Sicker <bo...@gmail.com> wrote:
> I put them in the translator in case extensions wanted to use them.
>
>
> On 10 September 2014 02:15, Remko Popma <re...@gmail.com> wrote:
>
>> Nice!
>>
>> Shall we move the remaining level constants to DefaultLevelConverter?
>> Also, do we need to define custom log4j levels FINE and FINEST? I thought
>> it might be good to remove them since these JUL levels already map to
>> built-in log4j levels DEBUG and TRACE.
>>
>> Sent from my iPhone
>>
>> > On 2014/09/10, at 15:44, mattsicker@apache.org wrote:
>> >
>> > Update LevelTranslator to use LevelConverter interface.
>> >
>> >
>> > Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
>> > Commit:
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/07e6faa3
>> > Tree:
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/07e6faa3
>> > Diff:
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/07e6faa3
>> >
>> > Branch: refs/heads/master
>> > Commit: 07e6faa32656571f18358e834e36b0a76d9917e6
>> > Parents: dc8be98
>> > Author: Matt Sicker <ma...@apache.org>
>> > Authored: Wed Sep 10 01:39:57 2014 -0500
>> > Committer: Matt Sicker <ma...@apache.org>
>> > Committed: Wed Sep 10 01:39:57 2014 -0500
>> >
>> > ----------------------------------------------------------------------
>> > .../logging/log4j/jul/LevelTranslator.java | 98
>> ++++++--------------
>> > .../logging/log4j/jul/LevelTranslatorTest.java | 31 ++++---
>> > 2 files changed, 45 insertions(+), 84 deletions(-)
>> > ----------------------------------------------------------------------
>> >
>> >
>> >
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/07e6faa3/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
>> > ----------------------------------------------------------------------
>> > diff --git
>> a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
>> b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
>> > index bc83457..8df429a 100644
>> > ---
>> a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
>> > +++
>> b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
>> > @@ -17,10 +17,11 @@
>> >
>> > package org.apache.logging.log4j.jul;
>> >
>> > -import java.util.IdentityHashMap;
>> > -import java.util.Map;
>> > -
>> > import org.apache.logging.log4j.Level;
>> > +import org.apache.logging.log4j.Logger;
>> > +import org.apache.logging.log4j.status.StatusLogger;
>> > +import org.apache.logging.log4j.util.LoaderUtil;
>> > +import org.apache.logging.log4j.util.PropertiesUtil;
>> >
>> > /**
>> > * Utility class to convert between JDK Levels and Log4j 2 Levels.
>> > @@ -29,37 +30,31 @@ import org.apache.logging.log4j.Level;
>> > */
>> > public final class LevelTranslator {
>> >
>> > - private static final int JDK_SEVERE =
>> java.util.logging.Level.SEVERE.intValue(); // ERROR
>> > - private static final int JDK_WARNING =
>> java.util.logging.Level.WARNING.intValue(); // WARN
>> > - private static final int JDK_INFO =
>> java.util.logging.Level.INFO.intValue(); // INFO
>> > - private static final int JDK_CONFIG =
>> java.util.logging.Level.CONFIG.intValue(); // INFO
>> > - private static final int JDK_FINE =
>> java.util.logging.Level.FINE.intValue(); // DEBUG
>> > - private static final int JDK_FINER =
>> java.util.logging.Level.FINER.intValue(); // DEBUG
>> > - private static final int JDK_FINEST =
>> java.util.logging.Level.FINEST.intValue(); // TRACE
>> > + public static final String LEVEL_CONVERTER_PROPERTY =
>> "log4j.jul.levelConverter";
>> > +
>> > + public static final Level FINEST = Level.forName("FINEST",
>> Level.TRACE.intLevel() + 100);
>> > + public static final Level FINER = Level.forName("FINER",
>> Level.TRACE.intLevel());
>> > + public static final Level FINE = Level.forName("FINE",
>> Level.DEBUG.intLevel());
>> > + public static final Level CONFIG = Level.forName("CONFIG",
>> Level.INFO.intLevel() + 50);
>> >
>> > - // standard level mappings
>> > - private static final Map<java.util.logging.Level, Level>
>> JDK_TO_LOG4J =
>> > - new IdentityHashMap<java.util.logging.Level, Level>(10);
>> > - private static final Map<Level, java.util.logging.Level>
>> LOG4J_TO_JDK =
>> > - new IdentityHashMap<Level, java.util.logging.Level>(10);
>> > + private static final Logger LOGGER = StatusLogger.getLogger();
>> > + private static final LevelConverter LEVEL_CONVERTER;
>> >
>> > static {
>> > - JDK_TO_LOG4J.put(java.util.logging.Level.OFF, Level.OFF);
>> > - JDK_TO_LOG4J.put(java.util.logging.Level.FINEST, Level.TRACE);
>> > - JDK_TO_LOG4J.put(java.util.logging.Level.FINER, Level.DEBUG);
>> > - JDK_TO_LOG4J.put(java.util.logging.Level.FINE, Level.DEBUG);
>> > - JDK_TO_LOG4J.put(java.util.logging.Level.CONFIG, Level.INFO);
>> > - JDK_TO_LOG4J.put(java.util.logging.Level.INFO, Level.INFO);
>> > - JDK_TO_LOG4J.put(java.util.logging.Level.WARNING, Level.WARN);
>> > - JDK_TO_LOG4J.put(java.util.logging.Level.SEVERE, Level.ERROR);
>> > - JDK_TO_LOG4J.put(java.util.logging.Level.ALL, Level.ALL);
>> > - LOG4J_TO_JDK.put(Level.OFF, java.util.logging.Level.OFF);
>> > - LOG4J_TO_JDK.put(Level.TRACE, java.util.logging.Level.FINEST);
>> > - LOG4J_TO_JDK.put(Level.DEBUG, java.util.logging.Level.FINE);
>> > - LOG4J_TO_JDK.put(Level.INFO, java.util.logging.Level.INFO);
>> > - LOG4J_TO_JDK.put(Level.WARN, java.util.logging.Level.WARNING);
>> > - LOG4J_TO_JDK.put(Level.ERROR, java.util.logging.Level.SEVERE);
>> > - LOG4J_TO_JDK.put(Level.ALL, java.util.logging.Level.ALL);
>> > + final String levelConverterClassName =
>> > +
>> PropertiesUtil.getProperties().getStringProperty(LEVEL_CONVERTER_PROPERTY);
>> > + if (levelConverterClassName != null) {
>> > + LevelConverter levelConverter;
>> > + try {
>> > + levelConverter =
>> LoaderUtil.newCheckedInstanceOf(levelConverterClassName,
>> LevelConverter.class);
>> > + } catch (final Exception e) {
>> > + LOGGER.error("Could not create custom LevelConverter
>> [{}].", levelConverterClassName, e);
>> > + levelConverter = new DefaultLevelConverter();
>> > + }
>> > + LEVEL_CONVERTER = levelConverter;
>> > + } else {
>> > + LEVEL_CONVERTER = new DefaultLevelConverter();
>> > + }
>> > }
>> >
>> > /**
>> > @@ -69,40 +64,7 @@ public final class LevelTranslator {
>> > * @return converted Level.
>> > */
>> > public static Level toLevel(final java.util.logging.Level level) {
>> > - final Level standardLevel = JDK_TO_LOG4J.get(level);
>> > - if (standardLevel != null) {
>> > - return standardLevel;
>> > - }
>> > - final int value = level.intValue();
>> > - if (value == Integer.MAX_VALUE) {
>> > - return Level.OFF;
>> > - }
>> > - if (value == Integer.MIN_VALUE) {
>> > - return Level.ALL;
>> > - }
>> > - if (value <= JDK_FINEST) { // up to 300
>> > - return Level.TRACE;
>> > - }
>> > - if (value <= JDK_FINER) { // 301 to 400
>> > - return Level.DEBUG;
>> > - }
>> > - if (value <= JDK_FINE) { // 401 to 500
>> > - return Level.DEBUG;
>> > - }
>> > - if (value <= JDK_CONFIG) { // 501 to 700
>> > - return Level.INFO;
>> > - }
>> > - if (value <= JDK_INFO) { // 701 to 800
>> > - return Level.INFO;
>> > - }
>> > - if (value <= JDK_WARNING) { // 801 to 900
>> > - return Level.WARN;
>> > - }
>> > - if (value <= JDK_SEVERE) { // 901 to 1000
>> > - return Level.ERROR;
>> > - }
>> > - // 1001+
>> > - return Level.FATAL;
>> > + return LEVEL_CONVERTER.toLevel(level);
>> > }
>> >
>> > /**
>> > @@ -112,11 +74,7 @@ public final class LevelTranslator {
>> > * @return converted Level.
>> > */
>> > public static java.util.logging.Level toJavaLevel(final Level
>> level) {
>> > - final java.util.logging.Level standardLevel =
>> LOG4J_TO_JDK.get(level);
>> > - if (standardLevel != null) {
>> > - return standardLevel;
>> > - }
>> > - return java.util.logging.Level.parse(level.name());
>> > + return LEVEL_CONVERTER.toJavaLevel(level);
>> > }
>> >
>> > private LevelTranslator() {
>> >
>> >
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/07e6faa3/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
>> > ----------------------------------------------------------------------
>> > diff --git
>> a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
>> b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
>> > index 744e296..3ab5e92 100644
>> > ---
>> a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
>> > +++
>> b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
>> > @@ -30,37 +30,40 @@ import static org.junit.Assert.*;
>> > @RunWith(Parameterized.class)
>> > public class LevelTranslatorTest {
>> >
>> > - private final java.util.logging.Level level;
>> > - private final Level expectedLevel;
>> > + private final java.util.logging.Level javaLevel;
>> > + private final Level log4jLevel;
>> >
>> > - public LevelTranslatorTest(final java.util.logging.Level level,
>> final Level expectedLevel) {
>> > - this.level = level;
>> > - this.expectedLevel = expectedLevel;
>> > + public LevelTranslatorTest(final java.util.logging.Level
>> javaLevel, final Level log4jLevel) {
>> > + this.javaLevel = javaLevel;
>> > + this.log4jLevel = log4jLevel;
>> > }
>> >
>> > @Parameterized.Parameters
>> > public static Collection<Object[]> data() {
>> > return Arrays.asList(
>> > new Object[][]{
>> > - {CustomJdkLevel.TEST, Level.INFO},
>> > - {CustomJdkLevel.DEFCON_2, Level.ERROR},
>> > - {CustomJdkLevel.DEFCON_1, Level.FATAL},
>> > {java.util.logging.Level.OFF, Level.OFF},
>> > {java.util.logging.Level.ALL, Level.ALL},
>> > {java.util.logging.Level.SEVERE, Level.ERROR},
>> > {java.util.logging.Level.WARNING, Level.WARN},
>> > {java.util.logging.Level.INFO, Level.INFO},
>> > - {java.util.logging.Level.CONFIG, Level.INFO},
>> > - {java.util.logging.Level.FINE, Level.DEBUG},
>> > - {java.util.logging.Level.FINER, Level.DEBUG},
>> > - {java.util.logging.Level.FINEST, Level.TRACE}
>> > + {java.util.logging.Level.CONFIG,
>> LevelTranslator.CONFIG},
>> > + {java.util.logging.Level.FINE, LevelTranslator.FINE},
>> > + {java.util.logging.Level.FINER, LevelTranslator.FINER},
>> > + {java.util.logging.Level.FINEST,
>> LevelTranslator.FINEST}
>> > }
>> > );
>> > }
>> >
>> > @Test
>> > public void testToLevel() throws Exception {
>> > - final Level actualLevel = LevelTranslator.toLevel(level);
>> > - assertEquals(expectedLevel, actualLevel);
>> > + final Level actualLevel = LevelTranslator.toLevel(javaLevel);
>> > + assertEquals(log4jLevel, actualLevel);
>> > + }
>> > +
>> > + @Test
>> > + public void testToJavaLevel() throws Exception {
>> > + final java.util.logging.Level actualLevel =
>> LevelTranslator.toJavaLevel(log4jLevel);
>> > + assertEquals(javaLevel, actualLevel);
>> > }
>> > }
>> > \ No newline at end of file
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-dev-help@logging.apache.org
>>
>>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>
Re: [2/6] git commit: Update LevelTranslator to use LevelConverter interface.
Posted by Matt Sicker <bo...@gmail.com>.
I put them in the translator in case extensions wanted to use them.
On 10 September 2014 02:15, Remko Popma <re...@gmail.com> wrote:
> Nice!
>
> Shall we move the remaining level constants to DefaultLevelConverter?
> Also, do we need to define custom log4j levels FINE and FINEST? I thought
> it might be good to remove them since these JUL levels already map to
> built-in log4j levels DEBUG and TRACE.
>
> Sent from my iPhone
>
> > On 2014/09/10, at 15:44, mattsicker@apache.org wrote:
> >
> > Update LevelTranslator to use LevelConverter interface.
> >
> >
> > Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
> > Commit:
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/07e6faa3
> > Tree:
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/07e6faa3
> > Diff:
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/07e6faa3
> >
> > Branch: refs/heads/master
> > Commit: 07e6faa32656571f18358e834e36b0a76d9917e6
> > Parents: dc8be98
> > Author: Matt Sicker <ma...@apache.org>
> > Authored: Wed Sep 10 01:39:57 2014 -0500
> > Committer: Matt Sicker <ma...@apache.org>
> > Committed: Wed Sep 10 01:39:57 2014 -0500
> >
> > ----------------------------------------------------------------------
> > .../logging/log4j/jul/LevelTranslator.java | 98 ++++++--------------
> > .../logging/log4j/jul/LevelTranslatorTest.java | 31 ++++---
> > 2 files changed, 45 insertions(+), 84 deletions(-)
> > ----------------------------------------------------------------------
> >
> >
> >
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/07e6faa3/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
> > ----------------------------------------------------------------------
> > diff --git
> a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
> b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
> > index bc83457..8df429a 100644
> > ---
> a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
> > +++
> b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
> > @@ -17,10 +17,11 @@
> >
> > package org.apache.logging.log4j.jul;
> >
> > -import java.util.IdentityHashMap;
> > -import java.util.Map;
> > -
> > import org.apache.logging.log4j.Level;
> > +import org.apache.logging.log4j.Logger;
> > +import org.apache.logging.log4j.status.StatusLogger;
> > +import org.apache.logging.log4j.util.LoaderUtil;
> > +import org.apache.logging.log4j.util.PropertiesUtil;
> >
> > /**
> > * Utility class to convert between JDK Levels and Log4j 2 Levels.
> > @@ -29,37 +30,31 @@ import org.apache.logging.log4j.Level;
> > */
> > public final class LevelTranslator {
> >
> > - private static final int JDK_SEVERE =
> java.util.logging.Level.SEVERE.intValue(); // ERROR
> > - private static final int JDK_WARNING =
> java.util.logging.Level.WARNING.intValue(); // WARN
> > - private static final int JDK_INFO =
> java.util.logging.Level.INFO.intValue(); // INFO
> > - private static final int JDK_CONFIG =
> java.util.logging.Level.CONFIG.intValue(); // INFO
> > - private static final int JDK_FINE =
> java.util.logging.Level.FINE.intValue(); // DEBUG
> > - private static final int JDK_FINER =
> java.util.logging.Level.FINER.intValue(); // DEBUG
> > - private static final int JDK_FINEST =
> java.util.logging.Level.FINEST.intValue(); // TRACE
> > + public static final String LEVEL_CONVERTER_PROPERTY =
> "log4j.jul.levelConverter";
> > +
> > + public static final Level FINEST = Level.forName("FINEST",
> Level.TRACE.intLevel() + 100);
> > + public static final Level FINER = Level.forName("FINER",
> Level.TRACE.intLevel());
> > + public static final Level FINE = Level.forName("FINE",
> Level.DEBUG.intLevel());
> > + public static final Level CONFIG = Level.forName("CONFIG",
> Level.INFO.intLevel() + 50);
> >
> > - // standard level mappings
> > - private static final Map<java.util.logging.Level, Level>
> JDK_TO_LOG4J =
> > - new IdentityHashMap<java.util.logging.Level, Level>(10);
> > - private static final Map<Level, java.util.logging.Level>
> LOG4J_TO_JDK =
> > - new IdentityHashMap<Level, java.util.logging.Level>(10);
> > + private static final Logger LOGGER = StatusLogger.getLogger();
> > + private static final LevelConverter LEVEL_CONVERTER;
> >
> > static {
> > - JDK_TO_LOG4J.put(java.util.logging.Level.OFF, Level.OFF);
> > - JDK_TO_LOG4J.put(java.util.logging.Level.FINEST, Level.TRACE);
> > - JDK_TO_LOG4J.put(java.util.logging.Level.FINER, Level.DEBUG);
> > - JDK_TO_LOG4J.put(java.util.logging.Level.FINE, Level.DEBUG);
> > - JDK_TO_LOG4J.put(java.util.logging.Level.CONFIG, Level.INFO);
> > - JDK_TO_LOG4J.put(java.util.logging.Level.INFO, Level.INFO);
> > - JDK_TO_LOG4J.put(java.util.logging.Level.WARNING, Level.WARN);
> > - JDK_TO_LOG4J.put(java.util.logging.Level.SEVERE, Level.ERROR);
> > - JDK_TO_LOG4J.put(java.util.logging.Level.ALL, Level.ALL);
> > - LOG4J_TO_JDK.put(Level.OFF, java.util.logging.Level.OFF);
> > - LOG4J_TO_JDK.put(Level.TRACE, java.util.logging.Level.FINEST);
> > - LOG4J_TO_JDK.put(Level.DEBUG, java.util.logging.Level.FINE);
> > - LOG4J_TO_JDK.put(Level.INFO, java.util.logging.Level.INFO);
> > - LOG4J_TO_JDK.put(Level.WARN, java.util.logging.Level.WARNING);
> > - LOG4J_TO_JDK.put(Level.ERROR, java.util.logging.Level.SEVERE);
> > - LOG4J_TO_JDK.put(Level.ALL, java.util.logging.Level.ALL);
> > + final String levelConverterClassName =
> > +
> PropertiesUtil.getProperties().getStringProperty(LEVEL_CONVERTER_PROPERTY);
> > + if (levelConverterClassName != null) {
> > + LevelConverter levelConverter;
> > + try {
> > + levelConverter =
> LoaderUtil.newCheckedInstanceOf(levelConverterClassName,
> LevelConverter.class);
> > + } catch (final Exception e) {
> > + LOGGER.error("Could not create custom LevelConverter
> [{}].", levelConverterClassName, e);
> > + levelConverter = new DefaultLevelConverter();
> > + }
> > + LEVEL_CONVERTER = levelConverter;
> > + } else {
> > + LEVEL_CONVERTER = new DefaultLevelConverter();
> > + }
> > }
> >
> > /**
> > @@ -69,40 +64,7 @@ public final class LevelTranslator {
> > * @return converted Level.
> > */
> > public static Level toLevel(final java.util.logging.Level level) {
> > - final Level standardLevel = JDK_TO_LOG4J.get(level);
> > - if (standardLevel != null) {
> > - return standardLevel;
> > - }
> > - final int value = level.intValue();
> > - if (value == Integer.MAX_VALUE) {
> > - return Level.OFF;
> > - }
> > - if (value == Integer.MIN_VALUE) {
> > - return Level.ALL;
> > - }
> > - if (value <= JDK_FINEST) { // up to 300
> > - return Level.TRACE;
> > - }
> > - if (value <= JDK_FINER) { // 301 to 400
> > - return Level.DEBUG;
> > - }
> > - if (value <= JDK_FINE) { // 401 to 500
> > - return Level.DEBUG;
> > - }
> > - if (value <= JDK_CONFIG) { // 501 to 700
> > - return Level.INFO;
> > - }
> > - if (value <= JDK_INFO) { // 701 to 800
> > - return Level.INFO;
> > - }
> > - if (value <= JDK_WARNING) { // 801 to 900
> > - return Level.WARN;
> > - }
> > - if (value <= JDK_SEVERE) { // 901 to 1000
> > - return Level.ERROR;
> > - }
> > - // 1001+
> > - return Level.FATAL;
> > + return LEVEL_CONVERTER.toLevel(level);
> > }
> >
> > /**
> > @@ -112,11 +74,7 @@ public final class LevelTranslator {
> > * @return converted Level.
> > */
> > public static java.util.logging.Level toJavaLevel(final Level level)
> {
> > - final java.util.logging.Level standardLevel =
> LOG4J_TO_JDK.get(level);
> > - if (standardLevel != null) {
> > - return standardLevel;
> > - }
> > - return java.util.logging.Level.parse(level.name());
> > + return LEVEL_CONVERTER.toJavaLevel(level);
> > }
> >
> > private LevelTranslator() {
> >
> >
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/07e6faa3/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
> > ----------------------------------------------------------------------
> > diff --git
> a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
> b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
> > index 744e296..3ab5e92 100644
> > ---
> a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
> > +++
> b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
> > @@ -30,37 +30,40 @@ import static org.junit.Assert.*;
> > @RunWith(Parameterized.class)
> > public class LevelTranslatorTest {
> >
> > - private final java.util.logging.Level level;
> > - private final Level expectedLevel;
> > + private final java.util.logging.Level javaLevel;
> > + private final Level log4jLevel;
> >
> > - public LevelTranslatorTest(final java.util.logging.Level level,
> final Level expectedLevel) {
> > - this.level = level;
> > - this.expectedLevel = expectedLevel;
> > + public LevelTranslatorTest(final java.util.logging.Level javaLevel,
> final Level log4jLevel) {
> > + this.javaLevel = javaLevel;
> > + this.log4jLevel = log4jLevel;
> > }
> >
> > @Parameterized.Parameters
> > public static Collection<Object[]> data() {
> > return Arrays.asList(
> > new Object[][]{
> > - {CustomJdkLevel.TEST, Level.INFO},
> > - {CustomJdkLevel.DEFCON_2, Level.ERROR},
> > - {CustomJdkLevel.DEFCON_1, Level.FATAL},
> > {java.util.logging.Level.OFF, Level.OFF},
> > {java.util.logging.Level.ALL, Level.ALL},
> > {java.util.logging.Level.SEVERE, Level.ERROR},
> > {java.util.logging.Level.WARNING, Level.WARN},
> > {java.util.logging.Level.INFO, Level.INFO},
> > - {java.util.logging.Level.CONFIG, Level.INFO},
> > - {java.util.logging.Level.FINE, Level.DEBUG},
> > - {java.util.logging.Level.FINER, Level.DEBUG},
> > - {java.util.logging.Level.FINEST, Level.TRACE}
> > + {java.util.logging.Level.CONFIG,
> LevelTranslator.CONFIG},
> > + {java.util.logging.Level.FINE, LevelTranslator.FINE},
> > + {java.util.logging.Level.FINER, LevelTranslator.FINER},
> > + {java.util.logging.Level.FINEST, LevelTranslator.FINEST}
> > }
> > );
> > }
> >
> > @Test
> > public void testToLevel() throws Exception {
> > - final Level actualLevel = LevelTranslator.toLevel(level);
> > - assertEquals(expectedLevel, actualLevel);
> > + final Level actualLevel = LevelTranslator.toLevel(javaLevel);
> > + assertEquals(log4jLevel, actualLevel);
> > + }
> > +
> > + @Test
> > + public void testToJavaLevel() throws Exception {
> > + final java.util.logging.Level actualLevel =
> LevelTranslator.toJavaLevel(log4jLevel);
> > + assertEquals(javaLevel, actualLevel);
> > }
> > }
> > \ No newline at end of file
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-dev-help@logging.apache.org
>
>
--
Matt Sicker <bo...@gmail.com>
Re: [2/6] git commit: Update LevelTranslator to use LevelConverter interface.
Posted by Remko Popma <re...@gmail.com>.
Nice!
Shall we move the remaining level constants to DefaultLevelConverter?
Also, do we need to define custom log4j levels FINE and FINEST? I thought it might be good to remove them since these JUL levels already map to built-in log4j levels DEBUG and TRACE.
Sent from my iPhone
> On 2014/09/10, at 15:44, mattsicker@apache.org wrote:
>
> Update LevelTranslator to use LevelConverter interface.
>
>
> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
> Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/07e6faa3
> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/07e6faa3
> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/07e6faa3
>
> Branch: refs/heads/master
> Commit: 07e6faa32656571f18358e834e36b0a76d9917e6
> Parents: dc8be98
> Author: Matt Sicker <ma...@apache.org>
> Authored: Wed Sep 10 01:39:57 2014 -0500
> Committer: Matt Sicker <ma...@apache.org>
> Committed: Wed Sep 10 01:39:57 2014 -0500
>
> ----------------------------------------------------------------------
> .../logging/log4j/jul/LevelTranslator.java | 98 ++++++--------------
> .../logging/log4j/jul/LevelTranslatorTest.java | 31 ++++---
> 2 files changed, 45 insertions(+), 84 deletions(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/07e6faa3/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
> ----------------------------------------------------------------------
> diff --git a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
> index bc83457..8df429a 100644
> --- a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
> +++ b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
> @@ -17,10 +17,11 @@
>
> package org.apache.logging.log4j.jul;
>
> -import java.util.IdentityHashMap;
> -import java.util.Map;
> -
> import org.apache.logging.log4j.Level;
> +import org.apache.logging.log4j.Logger;
> +import org.apache.logging.log4j.status.StatusLogger;
> +import org.apache.logging.log4j.util.LoaderUtil;
> +import org.apache.logging.log4j.util.PropertiesUtil;
>
> /**
> * Utility class to convert between JDK Levels and Log4j 2 Levels.
> @@ -29,37 +30,31 @@ import org.apache.logging.log4j.Level;
> */
> public final class LevelTranslator {
>
> - private static final int JDK_SEVERE = java.util.logging.Level.SEVERE.intValue(); // ERROR
> - private static final int JDK_WARNING = java.util.logging.Level.WARNING.intValue(); // WARN
> - private static final int JDK_INFO = java.util.logging.Level.INFO.intValue(); // INFO
> - private static final int JDK_CONFIG = java.util.logging.Level.CONFIG.intValue(); // INFO
> - private static final int JDK_FINE = java.util.logging.Level.FINE.intValue(); // DEBUG
> - private static final int JDK_FINER = java.util.logging.Level.FINER.intValue(); // DEBUG
> - private static final int JDK_FINEST = java.util.logging.Level.FINEST.intValue(); // TRACE
> + public static final String LEVEL_CONVERTER_PROPERTY = "log4j.jul.levelConverter";
> +
> + public static final Level FINEST = Level.forName("FINEST", Level.TRACE.intLevel() + 100);
> + public static final Level FINER = Level.forName("FINER", Level.TRACE.intLevel());
> + public static final Level FINE = Level.forName("FINE", Level.DEBUG.intLevel());
> + public static final Level CONFIG = Level.forName("CONFIG", Level.INFO.intLevel() + 50);
>
> - // standard level mappings
> - private static final Map<java.util.logging.Level, Level> JDK_TO_LOG4J =
> - new IdentityHashMap<java.util.logging.Level, Level>(10);
> - private static final Map<Level, java.util.logging.Level> LOG4J_TO_JDK =
> - new IdentityHashMap<Level, java.util.logging.Level>(10);
> + private static final Logger LOGGER = StatusLogger.getLogger();
> + private static final LevelConverter LEVEL_CONVERTER;
>
> static {
> - JDK_TO_LOG4J.put(java.util.logging.Level.OFF, Level.OFF);
> - JDK_TO_LOG4J.put(java.util.logging.Level.FINEST, Level.TRACE);
> - JDK_TO_LOG4J.put(java.util.logging.Level.FINER, Level.DEBUG);
> - JDK_TO_LOG4J.put(java.util.logging.Level.FINE, Level.DEBUG);
> - JDK_TO_LOG4J.put(java.util.logging.Level.CONFIG, Level.INFO);
> - JDK_TO_LOG4J.put(java.util.logging.Level.INFO, Level.INFO);
> - JDK_TO_LOG4J.put(java.util.logging.Level.WARNING, Level.WARN);
> - JDK_TO_LOG4J.put(java.util.logging.Level.SEVERE, Level.ERROR);
> - JDK_TO_LOG4J.put(java.util.logging.Level.ALL, Level.ALL);
> - LOG4J_TO_JDK.put(Level.OFF, java.util.logging.Level.OFF);
> - LOG4J_TO_JDK.put(Level.TRACE, java.util.logging.Level.FINEST);
> - LOG4J_TO_JDK.put(Level.DEBUG, java.util.logging.Level.FINE);
> - LOG4J_TO_JDK.put(Level.INFO, java.util.logging.Level.INFO);
> - LOG4J_TO_JDK.put(Level.WARN, java.util.logging.Level.WARNING);
> - LOG4J_TO_JDK.put(Level.ERROR, java.util.logging.Level.SEVERE);
> - LOG4J_TO_JDK.put(Level.ALL, java.util.logging.Level.ALL);
> + final String levelConverterClassName =
> + PropertiesUtil.getProperties().getStringProperty(LEVEL_CONVERTER_PROPERTY);
> + if (levelConverterClassName != null) {
> + LevelConverter levelConverter;
> + try {
> + levelConverter = LoaderUtil.newCheckedInstanceOf(levelConverterClassName, LevelConverter.class);
> + } catch (final Exception e) {
> + LOGGER.error("Could not create custom LevelConverter [{}].", levelConverterClassName, e);
> + levelConverter = new DefaultLevelConverter();
> + }
> + LEVEL_CONVERTER = levelConverter;
> + } else {
> + LEVEL_CONVERTER = new DefaultLevelConverter();
> + }
> }
>
> /**
> @@ -69,40 +64,7 @@ public final class LevelTranslator {
> * @return converted Level.
> */
> public static Level toLevel(final java.util.logging.Level level) {
> - final Level standardLevel = JDK_TO_LOG4J.get(level);
> - if (standardLevel != null) {
> - return standardLevel;
> - }
> - final int value = level.intValue();
> - if (value == Integer.MAX_VALUE) {
> - return Level.OFF;
> - }
> - if (value == Integer.MIN_VALUE) {
> - return Level.ALL;
> - }
> - if (value <= JDK_FINEST) { // up to 300
> - return Level.TRACE;
> - }
> - if (value <= JDK_FINER) { // 301 to 400
> - return Level.DEBUG;
> - }
> - if (value <= JDK_FINE) { // 401 to 500
> - return Level.DEBUG;
> - }
> - if (value <= JDK_CONFIG) { // 501 to 700
> - return Level.INFO;
> - }
> - if (value <= JDK_INFO) { // 701 to 800
> - return Level.INFO;
> - }
> - if (value <= JDK_WARNING) { // 801 to 900
> - return Level.WARN;
> - }
> - if (value <= JDK_SEVERE) { // 901 to 1000
> - return Level.ERROR;
> - }
> - // 1001+
> - return Level.FATAL;
> + return LEVEL_CONVERTER.toLevel(level);
> }
>
> /**
> @@ -112,11 +74,7 @@ public final class LevelTranslator {
> * @return converted Level.
> */
> public static java.util.logging.Level toJavaLevel(final Level level) {
> - final java.util.logging.Level standardLevel = LOG4J_TO_JDK.get(level);
> - if (standardLevel != null) {
> - return standardLevel;
> - }
> - return java.util.logging.Level.parse(level.name());
> + return LEVEL_CONVERTER.toJavaLevel(level);
> }
>
> private LevelTranslator() {
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/07e6faa3/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
> ----------------------------------------------------------------------
> diff --git a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
> index 744e296..3ab5e92 100644
> --- a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
> +++ b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
> @@ -30,37 +30,40 @@ import static org.junit.Assert.*;
> @RunWith(Parameterized.class)
> public class LevelTranslatorTest {
>
> - private final java.util.logging.Level level;
> - private final Level expectedLevel;
> + private final java.util.logging.Level javaLevel;
> + private final Level log4jLevel;
>
> - public LevelTranslatorTest(final java.util.logging.Level level, final Level expectedLevel) {
> - this.level = level;
> - this.expectedLevel = expectedLevel;
> + public LevelTranslatorTest(final java.util.logging.Level javaLevel, final Level log4jLevel) {
> + this.javaLevel = javaLevel;
> + this.log4jLevel = log4jLevel;
> }
>
> @Parameterized.Parameters
> public static Collection<Object[]> data() {
> return Arrays.asList(
> new Object[][]{
> - {CustomJdkLevel.TEST, Level.INFO},
> - {CustomJdkLevel.DEFCON_2, Level.ERROR},
> - {CustomJdkLevel.DEFCON_1, Level.FATAL},
> {java.util.logging.Level.OFF, Level.OFF},
> {java.util.logging.Level.ALL, Level.ALL},
> {java.util.logging.Level.SEVERE, Level.ERROR},
> {java.util.logging.Level.WARNING, Level.WARN},
> {java.util.logging.Level.INFO, Level.INFO},
> - {java.util.logging.Level.CONFIG, Level.INFO},
> - {java.util.logging.Level.FINE, Level.DEBUG},
> - {java.util.logging.Level.FINER, Level.DEBUG},
> - {java.util.logging.Level.FINEST, Level.TRACE}
> + {java.util.logging.Level.CONFIG, LevelTranslator.CONFIG},
> + {java.util.logging.Level.FINE, LevelTranslator.FINE},
> + {java.util.logging.Level.FINER, LevelTranslator.FINER},
> + {java.util.logging.Level.FINEST, LevelTranslator.FINEST}
> }
> );
> }
>
> @Test
> public void testToLevel() throws Exception {
> - final Level actualLevel = LevelTranslator.toLevel(level);
> - assertEquals(expectedLevel, actualLevel);
> + final Level actualLevel = LevelTranslator.toLevel(javaLevel);
> + assertEquals(log4jLevel, actualLevel);
> + }
> +
> + @Test
> + public void testToJavaLevel() throws Exception {
> + final java.util.logging.Level actualLevel = LevelTranslator.toJavaLevel(log4jLevel);
> + assertEquals(javaLevel, actualLevel);
> }
> }
> \ No newline at end of file
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org
[2/6] git commit: Update LevelTranslator to use LevelConverter
interface.
Posted by ma...@apache.org.
Update LevelTranslator to use LevelConverter interface.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/07e6faa3
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/07e6faa3
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/07e6faa3
Branch: refs/heads/master
Commit: 07e6faa32656571f18358e834e36b0a76d9917e6
Parents: dc8be98
Author: Matt Sicker <ma...@apache.org>
Authored: Wed Sep 10 01:39:57 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Wed Sep 10 01:39:57 2014 -0500
----------------------------------------------------------------------
.../logging/log4j/jul/LevelTranslator.java | 98 ++++++--------------
.../logging/log4j/jul/LevelTranslatorTest.java | 31 ++++---
2 files changed, 45 insertions(+), 84 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/07e6faa3/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
----------------------------------------------------------------------
diff --git a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
index bc83457..8df429a 100644
--- a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
+++ b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LevelTranslator.java
@@ -17,10 +17,11 @@
package org.apache.logging.log4j.jul;
-import java.util.IdentityHashMap;
-import java.util.Map;
-
import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.LoaderUtil;
+import org.apache.logging.log4j.util.PropertiesUtil;
/**
* Utility class to convert between JDK Levels and Log4j 2 Levels.
@@ -29,37 +30,31 @@ import org.apache.logging.log4j.Level;
*/
public final class LevelTranslator {
- private static final int JDK_SEVERE = java.util.logging.Level.SEVERE.intValue(); // ERROR
- private static final int JDK_WARNING = java.util.logging.Level.WARNING.intValue(); // WARN
- private static final int JDK_INFO = java.util.logging.Level.INFO.intValue(); // INFO
- private static final int JDK_CONFIG = java.util.logging.Level.CONFIG.intValue(); // INFO
- private static final int JDK_FINE = java.util.logging.Level.FINE.intValue(); // DEBUG
- private static final int JDK_FINER = java.util.logging.Level.FINER.intValue(); // DEBUG
- private static final int JDK_FINEST = java.util.logging.Level.FINEST.intValue(); // TRACE
+ public static final String LEVEL_CONVERTER_PROPERTY = "log4j.jul.levelConverter";
+
+ public static final Level FINEST = Level.forName("FINEST", Level.TRACE.intLevel() + 100);
+ public static final Level FINER = Level.forName("FINER", Level.TRACE.intLevel());
+ public static final Level FINE = Level.forName("FINE", Level.DEBUG.intLevel());
+ public static final Level CONFIG = Level.forName("CONFIG", Level.INFO.intLevel() + 50);
- // standard level mappings
- private static final Map<java.util.logging.Level, Level> JDK_TO_LOG4J =
- new IdentityHashMap<java.util.logging.Level, Level>(10);
- private static final Map<Level, java.util.logging.Level> LOG4J_TO_JDK =
- new IdentityHashMap<Level, java.util.logging.Level>(10);
+ private static final Logger LOGGER = StatusLogger.getLogger();
+ private static final LevelConverter LEVEL_CONVERTER;
static {
- JDK_TO_LOG4J.put(java.util.logging.Level.OFF, Level.OFF);
- JDK_TO_LOG4J.put(java.util.logging.Level.FINEST, Level.TRACE);
- JDK_TO_LOG4J.put(java.util.logging.Level.FINER, Level.DEBUG);
- JDK_TO_LOG4J.put(java.util.logging.Level.FINE, Level.DEBUG);
- JDK_TO_LOG4J.put(java.util.logging.Level.CONFIG, Level.INFO);
- JDK_TO_LOG4J.put(java.util.logging.Level.INFO, Level.INFO);
- JDK_TO_LOG4J.put(java.util.logging.Level.WARNING, Level.WARN);
- JDK_TO_LOG4J.put(java.util.logging.Level.SEVERE, Level.ERROR);
- JDK_TO_LOG4J.put(java.util.logging.Level.ALL, Level.ALL);
- LOG4J_TO_JDK.put(Level.OFF, java.util.logging.Level.OFF);
- LOG4J_TO_JDK.put(Level.TRACE, java.util.logging.Level.FINEST);
- LOG4J_TO_JDK.put(Level.DEBUG, java.util.logging.Level.FINE);
- LOG4J_TO_JDK.put(Level.INFO, java.util.logging.Level.INFO);
- LOG4J_TO_JDK.put(Level.WARN, java.util.logging.Level.WARNING);
- LOG4J_TO_JDK.put(Level.ERROR, java.util.logging.Level.SEVERE);
- LOG4J_TO_JDK.put(Level.ALL, java.util.logging.Level.ALL);
+ final String levelConverterClassName =
+ PropertiesUtil.getProperties().getStringProperty(LEVEL_CONVERTER_PROPERTY);
+ if (levelConverterClassName != null) {
+ LevelConverter levelConverter;
+ try {
+ levelConverter = LoaderUtil.newCheckedInstanceOf(levelConverterClassName, LevelConverter.class);
+ } catch (final Exception e) {
+ LOGGER.error("Could not create custom LevelConverter [{}].", levelConverterClassName, e);
+ levelConverter = new DefaultLevelConverter();
+ }
+ LEVEL_CONVERTER = levelConverter;
+ } else {
+ LEVEL_CONVERTER = new DefaultLevelConverter();
+ }
}
/**
@@ -69,40 +64,7 @@ public final class LevelTranslator {
* @return converted Level.
*/
public static Level toLevel(final java.util.logging.Level level) {
- final Level standardLevel = JDK_TO_LOG4J.get(level);
- if (standardLevel != null) {
- return standardLevel;
- }
- final int value = level.intValue();
- if (value == Integer.MAX_VALUE) {
- return Level.OFF;
- }
- if (value == Integer.MIN_VALUE) {
- return Level.ALL;
- }
- if (value <= JDK_FINEST) { // up to 300
- return Level.TRACE;
- }
- if (value <= JDK_FINER) { // 301 to 400
- return Level.DEBUG;
- }
- if (value <= JDK_FINE) { // 401 to 500
- return Level.DEBUG;
- }
- if (value <= JDK_CONFIG) { // 501 to 700
- return Level.INFO;
- }
- if (value <= JDK_INFO) { // 701 to 800
- return Level.INFO;
- }
- if (value <= JDK_WARNING) { // 801 to 900
- return Level.WARN;
- }
- if (value <= JDK_SEVERE) { // 901 to 1000
- return Level.ERROR;
- }
- // 1001+
- return Level.FATAL;
+ return LEVEL_CONVERTER.toLevel(level);
}
/**
@@ -112,11 +74,7 @@ public final class LevelTranslator {
* @return converted Level.
*/
public static java.util.logging.Level toJavaLevel(final Level level) {
- final java.util.logging.Level standardLevel = LOG4J_TO_JDK.get(level);
- if (standardLevel != null) {
- return standardLevel;
- }
- return java.util.logging.Level.parse(level.name());
+ return LEVEL_CONVERTER.toJavaLevel(level);
}
private LevelTranslator() {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/07e6faa3/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
----------------------------------------------------------------------
diff --git a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
index 744e296..3ab5e92 100644
--- a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
+++ b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/LevelTranslatorTest.java
@@ -30,37 +30,40 @@ import static org.junit.Assert.*;
@RunWith(Parameterized.class)
public class LevelTranslatorTest {
- private final java.util.logging.Level level;
- private final Level expectedLevel;
+ private final java.util.logging.Level javaLevel;
+ private final Level log4jLevel;
- public LevelTranslatorTest(final java.util.logging.Level level, final Level expectedLevel) {
- this.level = level;
- this.expectedLevel = expectedLevel;
+ public LevelTranslatorTest(final java.util.logging.Level javaLevel, final Level log4jLevel) {
+ this.javaLevel = javaLevel;
+ this.log4jLevel = log4jLevel;
}
@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(
new Object[][]{
- {CustomJdkLevel.TEST, Level.INFO},
- {CustomJdkLevel.DEFCON_2, Level.ERROR},
- {CustomJdkLevel.DEFCON_1, Level.FATAL},
{java.util.logging.Level.OFF, Level.OFF},
{java.util.logging.Level.ALL, Level.ALL},
{java.util.logging.Level.SEVERE, Level.ERROR},
{java.util.logging.Level.WARNING, Level.WARN},
{java.util.logging.Level.INFO, Level.INFO},
- {java.util.logging.Level.CONFIG, Level.INFO},
- {java.util.logging.Level.FINE, Level.DEBUG},
- {java.util.logging.Level.FINER, Level.DEBUG},
- {java.util.logging.Level.FINEST, Level.TRACE}
+ {java.util.logging.Level.CONFIG, LevelTranslator.CONFIG},
+ {java.util.logging.Level.FINE, LevelTranslator.FINE},
+ {java.util.logging.Level.FINER, LevelTranslator.FINER},
+ {java.util.logging.Level.FINEST, LevelTranslator.FINEST}
}
);
}
@Test
public void testToLevel() throws Exception {
- final Level actualLevel = LevelTranslator.toLevel(level);
- assertEquals(expectedLevel, actualLevel);
+ final Level actualLevel = LevelTranslator.toLevel(javaLevel);
+ assertEquals(log4jLevel, actualLevel);
+ }
+
+ @Test
+ public void testToJavaLevel() throws Exception {
+ final java.util.logging.Level actualLevel = LevelTranslator.toJavaLevel(log4jLevel);
+ assertEquals(javaLevel, actualLevel);
}
}
\ No newline at end of file
[5/6] git commit: Implement more JUL Logger methods.
Posted by ma...@apache.org.
Implement more JUL Logger methods.
- Prevents need to create LogRecord objects for every Message.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/6944f949
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/6944f949
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/6944f949
Branch: refs/heads/master
Commit: 6944f949a0eadd0792c3d53ec8586549bc5185c8
Parents: 2d1c0f8
Author: Matt Sicker <ma...@apache.org>
Authored: Wed Sep 10 01:43:46 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Wed Sep 10 01:43:46 2014 -0500
----------------------------------------------------------------------
.../org/apache/logging/log4j/jul/ApiLogger.java | 165 +++++++++++++++----
1 file changed, 135 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6944f949/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 fd8da21..e213076 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
@@ -22,7 +22,6 @@ import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
-import org.apache.logging.log4j.ThreadContext;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.spi.ExtendedLogger;
@@ -42,33 +41,13 @@ import org.apache.logging.log4j.spi.ExtendedLogger;
*/
public class ApiLogger extends Logger {
- private static final String FQCN = java.util.logging.Logger.class.getName();
-
- private static final String PREFIX = "log4j.jul.";
-
- /**
- * The {@link org.apache.logging.log4j.ThreadContext} key where the value of {@link java.util.logging.LogRecord#getThreadID()} will be stored.
- */
- public static final String THREAD_ID = PREFIX + "threadID";
-
- /**
- * The {@link org.apache.logging.log4j.ThreadContext} key where the value of {@link java.util.logging.LogRecord#getSequenceNumber()} will be stored.
- */
- public static final String SEQUENCE_NUMBER = PREFIX + "sequenceNumber";
-
- /**
- * The {@link org.apache.logging.log4j.ThreadContext} key where the name of the {@link java.util.logging.Level} will be stored. This is particularly useful
- * for custom Level implementations as well as for obtaining the exact Level that was used rather than the
- * equivalent Log4j {@link org.apache.logging.log4j.Level}.
- */
- public static final String LEVEL = PREFIX + "level";
-
- private final ExtendedLogger logger;
+ private final WrappedLogger logger;
+ private static final String FQCN = ApiLogger.class.getName();
ApiLogger(final ExtendedLogger logger) {
super(logger.getName(), null);
super.setLevel(LevelTranslator.toJavaLevel(logger.getLevel()));
- this.logger = logger;
+ this.logger = new WrappedLogger(logger);
}
@Override
@@ -76,16 +55,10 @@ public class ApiLogger extends Logger {
if (isFiltered(record)) {
return;
}
- ThreadContext.put(THREAD_ID, Integer.toString(record.getThreadID()));
- ThreadContext.put(SEQUENCE_NUMBER, Long.toString(record.getSequenceNumber()));
- ThreadContext.put(LEVEL, record.getLevel().getName());
final org.apache.logging.log4j.Level level = LevelTranslator.toLevel(record.getLevel());
final Message message = logger.getMessageFactory().newMessage(record.getMessage(), record.getParameters());
final Throwable thrown = record.getThrown();
logger.logIfEnabled(FQCN, level, null, message, thrown);
- ThreadContext.remove(THREAD_ID);
- ThreadContext.remove(SEQUENCE_NUMBER);
- ThreadContext.remove(LEVEL);
}
// support for Logger.getFilter()/Logger.setFilter()
@@ -127,4 +100,136 @@ public class ApiLogger extends Logger {
public void setParent(final Logger parent) {
throw new UnsupportedOperationException("Cannot set parent logger");
}
+
+ @Override
+ public void log(final Level level, final String msg) {
+ logger.log(LevelTranslator.toLevel(level), msg);
+ }
+
+ @Override
+ public void log(final Level level, final String msg, final Object param1) {
+ logger.log(LevelTranslator.toLevel(level), msg, param1);
+ }
+
+ @Override
+ public void log(final Level level, final String msg, final Object[] params) {
+ logger.log(LevelTranslator.toLevel(level), msg, params);
+ }
+
+ @Override
+ public void log(final Level level, final String msg, final Throwable thrown) {
+ logger.log(LevelTranslator.toLevel(level), msg, thrown);
+ }
+
+ @Override
+ public void logp(final Level level, final String sourceClass, final String sourceMethod, final String msg) {
+ log(level, msg);
+ }
+
+ @Override
+ public void logp(final Level level, final String sourceClass, final String sourceMethod, final String msg,
+ final Object param1) {
+ log(level, msg, param1);
+ }
+
+ @Override
+ public void logp(final Level level, final String sourceClass, final String sourceMethod, final String msg,
+ final Object[] params) {
+ log(level, msg, params);
+ }
+
+ @Override
+ public void logp(final Level level, final String sourceClass, final String sourceMethod, final String msg,
+ final Throwable thrown) {
+ log(level, msg, thrown);
+ }
+
+ @Override
+ public void logrb(final Level level, final String sourceClass, final String sourceMethod, final String bundleName,
+ final String msg) {
+ log(level, msg);
+ }
+
+ @Override
+ public void logrb(final Level level, final String sourceClass, final String sourceMethod, final String bundleName,
+ final String msg, final Object param1) {
+ log(level, msg, param1);
+ }
+
+ @Override
+ public void logrb(final Level level, final String sourceClass, final String sourceMethod, final String bundleName,
+ final String msg, final Object[] params) {
+ log(level, msg, params);
+ }
+
+ @Override
+ public void logrb(final Level level, final String sourceClass, final String sourceMethod, final String bundleName,
+ final String msg, final Throwable thrown) {
+ log(level, msg, thrown);
+ }
+
+ @Override
+ public void entering(final String sourceClass, final String sourceMethod) {
+ logger.entry();
+ }
+
+ @Override
+ public void entering(final String sourceClass, final String sourceMethod, final Object param1) {
+ logger.entry(param1);
+ }
+
+ @Override
+ public void entering(final String sourceClass, final String sourceMethod, final Object[] params) {
+ logger.entry(params);
+ }
+
+ @Override
+ public void exiting(final String sourceClass, final String sourceMethod) {
+ logger.exit();
+ }
+
+ @Override
+ public void exiting(final String sourceClass, final String sourceMethod, final Object result) {
+ logger.exit(result);
+ }
+
+ @Override
+ public void throwing(final String sourceClass, final String sourceMethod, final Throwable thrown) {
+ logger.throwing(thrown);
+ }
+
+ @Override
+ public void severe(final String msg) {
+ logger.logIfEnabled(FQCN, org.apache.logging.log4j.Level.ERROR, null, msg);
+ }
+
+ @Override
+ public void warning(final String msg) {
+ logger.logIfEnabled(FQCN, org.apache.logging.log4j.Level.WARN, null, msg);
+ }
+
+ @Override
+ public void info(final String msg) {
+ logger.logIfEnabled(FQCN, org.apache.logging.log4j.Level.INFO, null, msg);
+ }
+
+ @Override
+ public void config(final String msg) {
+ logger.logIfEnabled(FQCN, LevelTranslator.CONFIG, null, msg);
+ }
+
+ @Override
+ public void fine(final String msg) {
+ logger.logIfEnabled(FQCN, LevelTranslator.FINE, null, msg);
+ }
+
+ @Override
+ public void finer(final String msg) {
+ logger.logIfEnabled(FQCN, LevelTranslator.FINER, null, msg);
+ }
+
+ @Override
+ public void finest(final String msg) {
+ logger.logIfEnabled(FQCN, LevelTranslator.FINEST, null, msg);
+ }
}