Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To send Logback console output to standard error, set the ConsoleAppender‘s target to System.err and attach that appender to the logger whose events you want to redirect. If you omit target, Logback uses System.out.

Configure a ConsoleAppender to write to stderr

In logback.xml, set the target value exactly to System.err. Keep an encoder in the appender to define how each event is rendered:

<configuration>
  <appender name="STDERR" class="ch.qos.logback.core.ConsoleAppender">
    <target>System.err</target>
    <encoder>
      <pattern>%d{ISO8601} %-5level %logger - %msg%n</pattern>
    </encoder>
  </appender>

  <root level="INFO">
    <appender-ref ref="STDERR"/>
  </root>
</configuration>

This root configuration sends events at INFO level and above to the stderr console appender. Adjust the root level or attach the appender to a specific logger if only part of your application should use it. Logback documents System.out as the default target and System.err as the alternative (Logback ConsoleAppender manual).

Check why output may still appear on stdout

  • The target is missing or incorrect: the documented values are System.out and System.err. Use the exact spelling and capitalization System.err; other values are ignored by the target setter (Logback OutputStreamAppender API source).
  • A different appender is still attached: inspect the logger and root logger’s <appender-ref> entries. If an appender targeting stdout remains attached, events can still be written there as well.
  • The appender is attached at a different scope: verify that the logger producing the event uses the stderr appender, directly or through its logger hierarchy.

What changing the target does—and does not do

The target selects the Java console stream; it does not turn console logging into file logging. The encoder formats each event before it is written. Logback’s manual describes the console streams as being wrapped in an OutputStreamWriter and notes that output is buffered (Logback ConsoleAppender manual).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Logback warns that console output can be very slow, particularly in high-volume production systems. Sending it to stderr instead of stdout does not remove the cost of console output. Also, Logback’s stream setting alone does not determine how a container, framework, or service manager captures stderr; confirm that behavior in your deployment environment.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Is withJansi needed for stderr?

No. withJansi is an optional setting related to ANSI handling; it is separate from choosing the output stream. Set <target>System.err</target> to select stderr, and configure ANSI behavior only if your environment requires it (Logback ConsoleAppender manual).

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.