Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-15684 - redirect all logs for level ERROR and FATAL also to stderr #16054

Merged
merged 11 commits into from
Feb 29, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public void reconfigureLog4J() {
.addAttribute("target", "SYSTEM_OUT")
.add(layoutComponentBuilder));

builder.add(builder.newAppender("stderr", "Console")
.addAttribute("target", "SYSTEM_ERR")
.add(builder.newFilter("ThresholdFilter", Filter.Result.ACCEPT, Filter.Result.DENY).addAttribute("level", Level.ERROR))
.add(layoutComponentBuilder));

builder.add(newRollingFileAppenderComponent(builder, "R1", "1MB", _getLogFilePath.apply("trace"), pattern, Level.TRACE));
builder.add(newRollingFileAppenderComponent(builder, "R2", _maxLogFileSize, _getLogFilePath.apply("debug"), pattern, Level.DEBUG));
builder.add(newRollingFileAppenderComponent(builder, "R3", _maxLogFileSize, _getLogFilePath.apply("info"), pattern, Level.INFO));
Expand All @@ -92,6 +97,7 @@ public void reconfigureLog4J() {
builder.add(newRollingFileAppenderComponent(builder, "HTTPD", "1MB", _getLogFilePath.apply("httpd"), "%d{ISO8601} " + patternTail, Level.TRACE));

AppenderRefComponentBuilder consoleAppenderRef = builder.newAppenderRef("Console");
AppenderRefComponentBuilder stderrAppenderRef = builder.newAppenderRef("stderr");

// configure loggers:
List<AppenderRefComponentBuilder> appenderReferences = new ArrayList();
Expand All @@ -102,11 +108,12 @@ public void reconfigureLog4J() {
appenderReferences.add(builder.newAppenderRef("R5"));
appenderReferences.add(builder.newAppenderRef("R6"));
appenderReferences.add(consoleAppenderRef);
appenderReferences.add(stderrAppenderRef);

builder.add(newLoggerComponent(builder, "hex", appenderReferences));
builder.add(newLoggerComponent(builder, "water", appenderReferences));
builder.add(newLoggerComponent(builder, "ai.h2o", appenderReferences));
builder.add(builder.newRootLogger(String.valueOf(L4J_LVLS[_level])).add(consoleAppenderRef));
builder.add(builder.newRootLogger(String.valueOf(L4J_LVLS[_level])).add(consoleAppenderRef).add(stderrAppenderRef));

// Turn down the logging for some class hierarchies.
builder.add(newLoggerComponent(builder, "org.apache.http", appenderReferences, "WARN"));
Expand Down
5 changes: 5 additions & 0 deletions h2o-logging/impl-log4j2/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<Console name="stderr" target="SYSTEM_ERR"> <!-- 2 -->
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
<ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/> <!-- 3 -->
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
<AppenderRef ref="stderr"/>
</Root>
</Loggers>
</Configuration>
12 changes: 12 additions & 0 deletions scripts/jenkins/Makefile.jenkins
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ build-h2o-3:
exit 1; \
fi

test-logger-initialize-properly:
-java -jar build/h2o.jar -ip 127.0.0.1 -web_ip 10.20.30.40 > out.txt 2>&1
if [[ $$(grep "ERROR" out.txt | wc -l) == "2" ]]; then \
rm -f out.txt; \
echo "All good"; \
exit 0; \
else \
rm -f out.txt; \
echo "All LOG.error() should be also printed to std.err. The out.txt doesn't contain 2 ERRORs, please check the output."; \
exit 1; \
fi

warmup-caches:
./gradlew build compileTestJava -x test -x h2o-r:build $$ADDITIONAL_GRADLE_OPTS

Expand Down
4 changes: 4 additions & 0 deletions scripts/jenkins/groovy/defineTestStages.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,10 @@ def call(final pipelineContext) {
stageName: 'R4.0 Explain', target: 'test-r-explain', rVersion: '4.0.2',
timeoutValue: 180, component: pipelineContext.getBuildConfig().COMPONENT_R
],
[
stageName: 'LOGGER inicialization test', target: 'test-logger-initialize-properly', javaVersion: 8, timeoutValue: 1,
component: pipelineContext.getBuildConfig().COMPONENT_JAVA
]
]

def supportedHadoopDists = pipelineContext.getBuildConfig().getSupportedHadoopDistributions()
Expand Down
Loading