提交 6b082b55 编写于 作者: U Ufuk Celebi

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

上级 341c859c
/*
* 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();
}
}
...@@ -16,12 +16,20 @@ ...@@ -16,12 +16,20 @@
# limitations under the License. # limitations under the License.
################################################################################ ################################################################################
# Set root logger level to OFF and its only appender to A1. log4j.rootLogger=OFF
log4j.rootLogger=OFF, A1
# 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 # File (use 'file')
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n # -----------------------------------------------------------------------------
\ No newline at end of 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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册