You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2015/08/26 01:48:30 UTC

logging-log4j2 git commit: Test basic CustomLevel configuration and logging.

Repository: logging-log4j2
Updated Branches:
  refs/heads/master 8b10560c3 -> 8eb478a45


Test basic CustomLevel configuration and logging.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/8eb478a4
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/8eb478a4
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/8eb478a4

Branch: refs/heads/master
Commit: 8eb478a45159d3953048b6024b0da9f7ddeb2ef3
Parents: 8b10560
Author: ggregory <gg...@apache.org>
Authored: Tue Aug 25 16:48:27 2015 -0700
Committer: ggregory <gg...@apache.org>
Committed: Tue Aug 25 16:48:27 2015 -0700

----------------------------------------------------------------------
 .../logging/log4j/core/CustomLevelsTest.java    | 82 ++++++++++++++++++++
 .../src/test/resources/log4j-customLevels.xml   | 41 ++++++++++
 2 files changed, 123 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8eb478a4/log4j-core/src/test/java/org/apache/logging/log4j/core/CustomLevelsTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/CustomLevelsTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/CustomLevelsTest.java
new file mode 100644
index 0000000..4c61167
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/CustomLevelsTest.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core;
+
+import static org.hamcrest.Matchers.hasSize;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+
+import java.util.List;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.junit.InitialLoggerContext;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class CustomLevelsTest {
+
+    private static final String CONFIG = "log4j-customLevels.xml";
+    
+    @ClassRule
+    public static InitialLoggerContext context = new InitialLoggerContext(CONFIG);
+    
+    private ListAppender listAppender;
+    private Level diagLevel;
+    private Level noticeLevel;
+    private Level verboseLevel;
+
+    @Before
+    public void before() {
+        diagLevel = Level.getLevel("DIAG");
+        noticeLevel = Level.getLevel("NOTICE");
+        verboseLevel = Level.getLevel("VERBOSE");
+        listAppender = context.getListAppender("List1").clear();
+    }
+
+    @Test
+    public void testCustomLevelInts() {
+        assertEquals(350, diagLevel.intLevel());
+        assertEquals(450, noticeLevel.intLevel());
+        assertEquals(550, verboseLevel.intLevel());
+    }
+
+    @Test
+    public void testCustomLevelPresence() {
+        assertNotNull(diagLevel);
+        assertNotNull(noticeLevel);
+        assertNotNull(verboseLevel);
+    }
+
+    @Test
+    public void testLog() {
+        final Logger logger = context.getLogger();
+        final List<LogEvent> events = listAppender.getEvents();
+        assertThat(events, hasSize(0));
+        logger.debug("Hello, {}", "World");
+        assertThat(events, hasSize(1));
+        logger.log(diagLevel, "Hello DIAG");
+        assertThat(events, hasSize(2));
+        assertEquals(events.get(1).getLevel(), diagLevel);
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8eb478a4/log4j-core/src/test/resources/log4j-customLevels.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-customLevels.xml b/log4j-core/src/test/resources/log4j-customLevels.xml
new file mode 100644
index 0000000..4d5a8fe
--- /dev/null
+++ b/log4j-core/src/test/resources/log4j-customLevels.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+
+-->
+<Configuration status="DEBUG" name="TestCustomLevels">
+
+  <CustomLevels>
+    <CustomLevel name="DIAG" intLevel="350" />
+    <CustomLevel name="NOTICE" intLevel="450" />
+    <CustomLevel name="VERBOSE" intLevel="550" />
+  </CustomLevels>
+  
+  <Appenders>
+    <Console name="STDOUT">
+      <PatternLayout pattern="%m%n"/>
+    </Console>
+    <List name="List1"/>
+  </Appenders>
+
+  <Loggers>
+    <Root level="DEBUG">
+      <AppenderRef ref="STDOUT"/>
+      <AppenderRef ref="List1"/>
+    </Root>
+  </Loggers>
+
+</Configuration>
\ No newline at end of file