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/22 06:03:31 UTC
[7/7] logging-log4j2 git commit: LOG4J2-1100 Unable to configure
Multiple triggering policies on rolling file appender using yaml
configuration file. Add tests for XML, JSON,
and YAML. The YAML test fails and is @Ignore'd.
LOG4J2-1100
Unable to configure Multiple triggering policies on rolling file
appender using yaml configuration file. Add tests for XML, JSON, and
YAML. The YAML test fails and is @Ignore'd.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/36c65b3c
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/36c65b3c
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/36c65b3c
Branch: refs/heads/master
Commit: 36c65b3ca40954da8700bc8760a6146aab372b7f
Parents: 6c828b9
Author: ggregory <gg...@apache.org>
Authored: Fri Aug 21 21:03:18 2015 -0700
Committer: ggregory <gg...@apache.org>
Committed: Fri Aug 21 21:03:18 2015 -0700
----------------------------------------------------------------------
.../core/config/AbstractLog4j2_1100Test.java | 70 ++++++++++++++++++++
.../core/config/JiraLog4j2_1100JsonTest.java | 26 ++++++++
.../core/config/JiraLog4j2_1100XmlTest.java | 26 ++++++++
.../core/config/JiraLog4j2_1100YamlTest.java | 29 ++++++++
.../src/test/resources/LOG4J2-1100/log4j2.json | 42 ++++++++++++
.../src/test/resources/LOG4J2-1100/log4j2.xml | 22 ++++++
.../src/test/resources/LOG4J2-1100/log4j2.yaml | 30 +++++++++
7 files changed, 245 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/36c65b3c/log4j-core/src/test/java/org/apache/logging/log4j/core/config/AbstractLog4j2_1100Test.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/AbstractLog4j2_1100Test.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/AbstractLog4j2_1100Test.java
new file mode 100644
index 0000000..6a62f07
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/AbstractLog4j2_1100Test.java
@@ -0,0 +1,70 @@
+/*
+ * 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.config;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import org.apache.logging.log4j.core.appender.RollingFileAppender;
+import org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy;
+import org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy;
+import org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy;
+import org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy;
+import org.apache.logging.log4j.junit.InitialLoggerContext;
+import org.junit.Rule;
+import org.junit.Test;
+
+public abstract class AbstractLog4j2_1100Test {
+
+ @Rule
+ public InitialLoggerContext context = new InitialLoggerContext(getConfigurationResource());
+
+ protected abstract String getConfigurationResource();
+
+ @Test
+ public void test() {
+ final Configuration configuration = context.getConfiguration();
+ assertNotNull(configuration);
+ final RollingFileAppender appender = (RollingFileAppender) configuration.getAppender("File");
+ assertNotNull(appender);
+ final CompositeTriggeringPolicy compositeTriggeringPolicy = (CompositeTriggeringPolicy) appender
+ .getTriggeringPolicy();
+ assertNotNull(compositeTriggeringPolicy);
+ final TriggeringPolicy[] triggeringPolicies = compositeTriggeringPolicy.getTriggeringPolicies();
+ assertEquals(2, triggeringPolicies.length);
+ SizeBasedTriggeringPolicy sizeBasedTriggeringPolicy = null;
+ TimeBasedTriggeringPolicy timeBasedTriggeringPolicy = null;
+ for (TriggeringPolicy triggeringPolicy : triggeringPolicies) {
+ if (triggeringPolicy instanceof TimeBasedTriggeringPolicy) {
+ timeBasedTriggeringPolicy = (TimeBasedTriggeringPolicy) triggeringPolicy;
+
+ }
+ if (triggeringPolicy instanceof SizeBasedTriggeringPolicy) {
+ sizeBasedTriggeringPolicy = (SizeBasedTriggeringPolicy) triggeringPolicy;
+ assertEquals(100 * 1024 * 1024, sizeBasedTriggeringPolicy.getMaxFileSize());
+ }
+ }
+ if (timeBasedTriggeringPolicy == null) {
+ fail("Missing TimeBasedTriggeringPolicy");
+ }
+ if (sizeBasedTriggeringPolicy == null) {
+ fail("Missing SizeBasedTriggeringPolicy");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/36c65b3c/log4j-core/src/test/java/org/apache/logging/log4j/core/config/JiraLog4j2_1100JsonTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/JiraLog4j2_1100JsonTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/JiraLog4j2_1100JsonTest.java
new file mode 100644
index 0000000..928d093
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/JiraLog4j2_1100JsonTest.java
@@ -0,0 +1,26 @@
+/*
+ * 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.config;
+
+public class JiraLog4j2_1100JsonTest extends AbstractLog4j2_1100Test {
+
+ protected String getConfigurationResource() {
+ return "LOG4J2-1100/log4j2.json";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/36c65b3c/log4j-core/src/test/java/org/apache/logging/log4j/core/config/JiraLog4j2_1100XmlTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/JiraLog4j2_1100XmlTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/JiraLog4j2_1100XmlTest.java
new file mode 100644
index 0000000..bb53619
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/JiraLog4j2_1100XmlTest.java
@@ -0,0 +1,26 @@
+/*
+ * 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.config;
+
+public class JiraLog4j2_1100XmlTest extends AbstractLog4j2_1100Test {
+
+ protected String getConfigurationResource() {
+ return "LOG4J2-1100/log4j2.xml";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/36c65b3c/log4j-core/src/test/java/org/apache/logging/log4j/core/config/JiraLog4j2_1100YamlTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/JiraLog4j2_1100YamlTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/JiraLog4j2_1100YamlTest.java
new file mode 100644
index 0000000..f58e25f
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/JiraLog4j2_1100YamlTest.java
@@ -0,0 +1,29 @@
+/*
+ * 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.config;
+
+import org.junit.Ignore;
+
+@Ignore
+public class JiraLog4j2_1100YamlTest extends AbstractLog4j2_1100Test {
+
+ protected String getConfigurationResource() {
+ return "LOG4J2-1100/log4j2.yaml";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/36c65b3c/log4j-core/src/test/resources/LOG4J2-1100/log4j2.json
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/LOG4J2-1100/log4j2.json b/log4j-core/src/test/resources/LOG4J2-1100/log4j2.json
new file mode 100644
index 0000000..d265cfb
--- /dev/null
+++ b/log4j-core/src/test/resources/LOG4J2-1100/log4j2.json
@@ -0,0 +1,42 @@
+{
+ "configuration": {
+ "status": "warn",
+ "appenders": {
+ "Console": {
+ "name": "Console",
+ "target": "SYSTEM_OUT",
+ "PatternLayout": {
+ "pattern": "%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"
+ }
+ },
+ "RollingFile": {
+ "name": "File",
+ "fileName": "${sys:user.home}/.btat/btat.log",
+ "filePattern": "${sys:user.home}/.btat/logs/btat-%d{yyyy-MM}-%i.log.gz",
+ "PatternLayout": {
+ "pattern": "%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"
+ },
+ "Policies": {
+ "TimeBasedTriggeringPolicy": {
+ "interval": "7"
+ },
+ "SizeBasedTriggeringPolicy": {
+ "size": "100 MB"
+ }
+ },
+ "DefaultRolloverStrategy": {
+ "max": "20"
+ }
+ }
+ },
+ "loggers": {
+ "Root": {
+ "level": "info",
+ "AppenderRef": [
+ { "ref": "Console" },
+ { "ref": "File" }
+ ]
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/36c65b3c/log4j-core/src/test/resources/LOG4J2-1100/log4j2.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/LOG4J2-1100/log4j2.xml b/log4j-core/src/test/resources/LOG4J2-1100/log4j2.xml
new file mode 100644
index 0000000..3d29dbc
--- /dev/null
+++ b/log4j-core/src/test/resources/LOG4J2-1100/log4j2.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="WARN">
+ <Appenders>
+ <Console name="Console" target="SYSTEM_OUT">
+ <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
+ </Console>
+ <RollingFile name="File" fileName="${sys:user.home}/.btat/btat.log" filePattern="${sys:user.home}/.btat/logs/btat-%d{yyyy-MM}-%i.log.gz">
+ <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
+ <Policies>
+ <TimeBasedTriggeringPolicy interval="7" />
+ <SizeBasedTriggeringPolicy size="100 MB"/>
+ </Policies>
+ <DefaultRolloverStrategy max="20" />
+ </RollingFile>
+ </Appenders>
+ <Loggers>
+ <Root level="info">
+ <AppenderRef ref="Console"/>
+ <AppenderRef ref="File"/>
+ </Root>
+ </Loggers>
+</Configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/36c65b3c/log4j-core/src/test/resources/LOG4J2-1100/log4j2.yaml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/LOG4J2-1100/log4j2.yaml b/log4j-core/src/test/resources/LOG4J2-1100/log4j2.yaml
new file mode 100644
index 0000000..523252c
--- /dev/null
+++ b/log4j-core/src/test/resources/LOG4J2-1100/log4j2.yaml
@@ -0,0 +1,30 @@
+Configuration:
+ status: warn
+
+ Appenders:
+ Console:
+ - name: Console
+ target: SYSTEM_OUT
+ PatternLayout:
+ Pattern: "%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"
+ RollingFile:
+ - name: File
+ fileName: "${sys:user.home}/.btat/btat.log"
+ filePattern: "${sys:user.home}/.btat/logs/btat-%d{yyyy-MM}-%i.log.gz"
+ PatternLayout:
+ Pattern: "%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"
+ Policies:
+ - TimeBasedTriggeringPolicy:
+ interval: 7
+ - SizeBasedTriggeringPolicy:
+ size: 100 MB
+ DefaultRolloverStrategy:
+ max: 20
+
+ Loggers:
+ Root:
+ level: info
+ AppenderRef:
+ - ref: Console
+ - ref: File
+
\ No newline at end of file