flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject [1/3] flink git commit: [builds] Add logger layout to prefix log output with Maven fork number
Date Thu, 19 Feb 2015 15:22:18 GMT
Repository: flink
Updated Branches:
  refs/heads/master a673e7ba6 -> 6c01598a3


[builds] Add logger layout to prefix log output with Maven fork number


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/6b082b55
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/6b082b55
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/6b082b55

Branch: refs/heads/master
Commit: 6b082b556242b08d19dc619d5339aa862cd0d1c4
Parents: 341c859
Author: Ufuk Celebi <uce@apache.org>
Authored: Mon Feb 16 16:40:49 2015 +0100
Committer: Ufuk Celebi <uce@apache.org>
Committed: Thu Feb 19 12:08:58 2015 +0100

----------------------------------------------------------------------
 .../flink/util/MavenForkNumberPrefixLayout.java | 70 ++++++++++++++++++++
 .../src/test/resources/log4j-test.properties    | 22 ++++--
 2 files changed, 85 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/6b082b55/flink-core/src/main/java/org/apache/flink/util/MavenForkNumberPrefixLayout.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/util/MavenForkNumberPrefixLayout.java
b/flink-core/src/main/java/org/apache/flink/util/MavenForkNumberPrefixLayout.java
new file mode 100644
index 0000000..8d16458
--- /dev/null
+++ b/flink-core/src/main/java/org/apache/flink/util/MavenForkNumberPrefixLayout.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.flink.util;
+
+import org.apache.log4j.PatternLayout;
+import org.apache.log4j.spi.LoggingEvent;
+
+/**
+ * The logging layout used to prefix each log event with the Maven fork number.
+ * <p>
+ * Use this layout when running tests via Maven in parallel and logging to the Console. When
logging
+ * to a file, you can use a separate file for each fork.
+ */
+public class MavenForkNumberPrefixLayout extends PatternLayout {
+
+	/** Property name used to set fork number of the forked JVM. */
+	private static final String PROPERTY = "mvn.forkNumber";
+
+	private final int prefixLength;
+
+	private final StringBuilder stringBuilder;
+
+	public MavenForkNumberPrefixLayout() {
+		super();
+
+		String prefix = System.getProperty(PROPERTY);
+
+		if (prefix != null) {
+			prefix += " > ";
+
+			prefixLength = prefix.length();
+
+			stringBuilder = new StringBuilder(512);
+			stringBuilder.append(prefix);
+		}
+		else {
+			prefixLength = 0;
+			stringBuilder = null;
+		}
+	}
+
+	@Override
+	public String format(LoggingEvent event) {
+		if (prefixLength == 0) {
+			return super.format(event);
+		}
+
+		stringBuilder.setLength(prefixLength);
+
+		stringBuilder.append(super.format(event));
+
+		return stringBuilder.toString();
+	}
+}

http://git-wip-us.apache.org/repos/asf/flink/blob/6b082b55/flink-runtime/src/test/resources/log4j-test.properties
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/resources/log4j-test.properties b/flink-runtime/src/test/resources/log4j-test.properties
index 04ec355..7a9f6ba 100644
--- a/flink-runtime/src/test/resources/log4j-test.properties
+++ b/flink-runtime/src/test/resources/log4j-test.properties
@@ -16,12 +16,20 @@
 # limitations under the License.
 ################################################################################
 
-# Set root logger level to OFF and its only appender to A1.
-log4j.rootLogger=OFF, A1
+log4j.rootLogger=OFF
 
-# A1 is set to be a ConsoleAppender.
-log4j.appender.A1=org.apache.log4j.ConsoleAppender
+# -----------------------------------------------------------------------------
+# Console (use 'console')
+# -----------------------------------------------------------------------------
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout=org.apache.flink.util.MavenForkNumberPrefixLayout
+log4j.appender.console.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p %-60c %x - %m%n
 
-# A1 uses PatternLayout.
-log4j.appender.A1.layout=org.apache.log4j.PatternLayout
-log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
\ No newline at end of file
+# -----------------------------------------------------------------------------
+# File (use 'file')
+# -----------------------------------------------------------------------------
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.file=${log.file}
+log4j.appender.file.append=false
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p %-60c %x - %m%n
\ No newline at end of file


Mime
View raw message