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 21:31:54 UTC

logging-log4j2 git commit: Add org.apache.logging.log4j.core.CustomLevelsWithFiltersTest.

Repository: logging-log4j2
Updated Branches:
  refs/heads/master 134d47949 -> 0024c8a64


Add org.apache.logging.log4j.core.CustomLevelsWithFiltersTest.

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

Branch: refs/heads/master
Commit: 0024c8a6479b857e4d96fb915eb5c4932f946650
Parents: 134d479
Author: ggregory <gg...@apache.org>
Authored: Wed Aug 26 12:31:51 2015 -0700
Committer: ggregory <gg...@apache.org>
Committed: Wed Aug 26 12:31:51 2015 -0700

----------------------------------------------------------------------
 .../log4j/core/CustomLevelsWithFiltersTest.java | 87 ++++++++++++++++++++
 .../resources/log4j-customLevelsWithFilters.xml | 25 ++++++
 2 files changed, 112 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0024c8a6/log4j-core/src/test/java/org/apache/logging/log4j/core/CustomLevelsWithFiltersTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/CustomLevelsWithFiltersTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/CustomLevelsWithFiltersTest.java
new file mode 100644
index 0000000..d7f62ba
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/CustomLevelsWithFiltersTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.List;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.appender.FileAppender;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.filter.CompositeFilter;
+import org.apache.logging.log4j.core.filter.ThresholdFilter;
+import org.apache.logging.log4j.junit.InitialLoggerContext;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class CustomLevelsWithFiltersTest {
+
+    private static final String CONFIG = "log4j-customLevelsWithFilters.xml";
+
+    @ClassRule
+    public static InitialLoggerContext context = new InitialLoggerContext(CONFIG);
+
+    private Level infom1Level;
+    private Level infop1Level;
+
+    @Before
+    public void before() {
+        infom1Level = Level.getLevel("INFOM1");
+        infop1Level = Level.getLevel("INFOP1");
+    }
+
+    @Test
+    public void testConfiguration() {
+        final Configuration configuration = context.getConfiguration();
+        assertNotNull(configuration);
+        final FileAppender appender = configuration.getAppender("info");
+        assertNotNull(appender);
+        final CompositeFilter compFilter = (CompositeFilter) appender.getFilter();
+        assertNotNull(compFilter);
+        final List<Filter> filterList = compFilter.getFilters();
+        assertNotNull(filterList);
+        boolean foundLevel = false;
+        for (final Filter filter : filterList) {
+            final ThresholdFilter tFilter = (ThresholdFilter) filter;
+            if (infom1Level.equals(tFilter.getLevel())) {
+                foundLevel = true;
+                break;
+            }
+        }
+        Assert.assertTrue("Level not found: " + infom1Level, foundLevel);
+    }
+
+    @Test
+    public void testCustomLevelInts() {
+        assertEquals(399, infom1Level.intLevel());
+        assertEquals(401, infop1Level.intLevel());
+    }
+
+    @Test
+    public void testCustomLevelPresence() {
+        assertNotNull(infom1Level);
+        assertNotNull(infop1Level);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0024c8a6/log4j-core/src/test/resources/log4j-customLevelsWithFilters.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-customLevelsWithFilters.xml b/log4j-core/src/test/resources/log4j-customLevelsWithFilters.xml
new file mode 100644
index 0000000..89cd032
--- /dev/null
+++ b/log4j-core/src/test/resources/log4j-customLevelsWithFilters.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="trace" verbose="true">
+  <CustomLevels>
+    <CustomLevel name="INFOM1" intLevel="399" />
+    <CustomLevel name="INFOP1" intLevel="401" />
+  </CustomLevels>
+  <Appenders>
+    <File name="info" fileName="target/info.log">
+      <PatternLayout>
+        <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
+      </PatternLayout>
+      <Filters>
+        <ThresholdFilter level="INFOM1" onMatch="DENY" onMismatch="NEUTRAL" />
+        <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY" />
+      </Filters>
+    </File>
+  </Appenders>
+  <Loggers>
+    <Logger name="HelloWorld" level="ALL">
+      <AppenderRef ref="info" />
+    </Logger>
+    <Root>
+    </Root>
+  </Loggers>
+</Configuration>