Repository: logging-log4j2 Updated Branches: refs/heads/master 8eb478a45 -> 255a41858
Add org.apache.logging.log4j.core.CustomLevelsOverrideTest Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/255a4185 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/255a4185 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/255a4185 Branch: refs/heads/master Commit: 255a418587ca57098bb9bf8060a24d0acaecb989 Parents: 8eb478a Author: ggregory <[email protected]> Authored: Tue Aug 25 16:56:24 2015 -0700 Committer: ggregory <[email protected]> Committed: Tue Aug 25 16:56:24 2015 -0700 ---------------------------------------------------------------------- .../log4j/core/CustomLevelsOverrideTest.java | 93 ++++++++++++++++++++ .../logging/log4j/core/log4j-customLevels.xml | 41 +++++++++ .../resources/log4j-customLevelsOverride.xml | 42 +++++++++ 3 files changed, 176 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/255a4185/log4j-core/src/test/java/org/apache/logging/log4j/core/CustomLevelsOverrideTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/CustomLevelsOverrideTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/CustomLevelsOverrideTest.java new file mode 100644 index 0000000..bca0482 --- /dev/null +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/CustomLevelsOverrideTest.java @@ -0,0 +1,93 @@ +/* + * 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.assertNotEquals; +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 CustomLevelsOverrideTest { + + private static final String CONFIG = "log4j-customLevels.xml"; + + @ClassRule + public static InitialLoggerContext context = new InitialLoggerContext(CONFIG); + + private ListAppender listAppender; + private Level warnLevel; + private Level infoLevel; + private Level debugLevel; + + @Before + public void before() { + warnLevel = Level.getLevel("WARN"); + infoLevel = Level.getLevel("INFO"); + debugLevel = Level.getLevel("DEBUG"); + listAppender = context.getListAppender("List1").clear(); + } + + @Test + public void testCustomLevelInts() { + // assertEquals(350, warnLevel.intLevel()); + // assertEquals(450, infoLevel.intLevel()); + // assertEquals(550, debugLevel.intLevel()); + assertNotEquals(350, warnLevel.intLevel()); + assertNotEquals(450, infoLevel.intLevel()); + assertNotEquals(550, debugLevel.intLevel()); + } + + @Test + public void testCustomLevelPresence() { + assertNotNull(warnLevel); + assertNotNull(infoLevel); + assertNotNull(debugLevel); + } + + @Test + public void testCustomLevelVsStdLevel() { + assertEquals(Level.WARN, warnLevel); + assertEquals(Level.INFO, infoLevel); + assertEquals(Level.DEBUG, debugLevel); + } + + @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(warnLevel, "Hello DIAG"); + assertThat(events, hasSize(2)); + assertEquals(events.get(1).getLevel(), warnLevel); + + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/255a4185/log4j-core/src/test/java/org/apache/logging/log4j/core/log4j-customLevels.xml ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/log4j-customLevels.xml b/log4j-core/src/test/java/org/apache/logging/log4j/core/log4j-customLevels.xml new file mode 100644 index 0000000..4d5a8fe --- /dev/null +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/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 http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/255a4185/log4j-core/src/test/resources/log4j-customLevelsOverride.xml ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/resources/log4j-customLevelsOverride.xml b/log4j-core/src/test/resources/log4j-customLevelsOverride.xml new file mode 100644 index 0000000..8719bb3 --- /dev/null +++ b/log4j-core/src/test/resources/log4j-customLevelsOverride.xml @@ -0,0 +1,42 @@ +<?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="TestCustomLevelsOverride"> + + <!-- Test overriding the int level of a standard level --> + <CustomLevels> + <CustomLevel name="WARN" intLevel="350" /> + <CustomLevel name="INFO" intLevel="450" /> + <CustomLevel name="DEBUG" 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
