Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.status;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class StatusLoggerTest {
private final PrintStream origOut = System.out;
private final PrintStream origErr = System.err;
private ByteArrayOutputStream outBuf;
private ByteArrayOutputStream errBuf;

@BeforeEach
void setupStreams() {
outBuf = new ByteArrayOutputStream();
errBuf = new ByteArrayOutputStream();
System.setOut(new PrintStream(outBuf));
System.setErr(new PrintStream(errBuf));
}

@AfterEach
void resetStreams() {
System.setOut(origOut);
System.setErr(origErr);
}

@Test
void status_logger_writes_to_stderr_by_default() {
StatusLogger statusLogger = new StatusLogger();
statusLogger.error("Test message");

assertEquals("", outBuf.toString());
assertThat(errBuf.toString()).contains("Test message");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ private static final class InstanceHolder {
StatusLogger.class.getSimpleName(),
ParameterizedNoReferenceMessageFactory.INSTANCE,
Config.getInstance(),
new StatusConsoleListener(requireNonNull(Config.getInstance().fallbackListenerLevel)));
new StatusConsoleListener(requireNonNull(Config.getInstance().fallbackListenerLevel), System.err));
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/changelog/.2.x.x/3665_fix_StatusLogger_writing_to_stdout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://logging.apache.org/xml/ns"
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
type="fixed">
<issue id="3665" link="https://github.com/apache/logging-log4j2/issues/3665"/>
<description format="asciidoc">
StatusLogger now writes to standard error by default. This fixes a regression introduced in 2.23.0.
</description>
</entry>