DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • New ORM Framework for Kotlin
  • How To Build Web Service Using Spring Boot 2.x
  • How to Connect to Splunk Through Anypoint Studio in 10 Steps
  • Your Application Has an Unindexed Attack Surface. Do You Know What’s in It?

Trending

  • Replay, Scheduling, and Throttling: Engineering a Self-Service Kafka Streaming Tool at Scale
  • Putting Guardrails Around What Your AI Agent Is Allowed to Touch
  • Beyond @Transactional: Solving the Dual-Write Problem in Distributed Microservices
  • Multi-Agent Orchestration on AWS With AgentCore Runtime and A2A

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Languages
  4. Redirect Logging Output to Standard Error with Logback

Redirect Logging Output to Standard Error with Logback

Learn how to redirect a logging output to a standard error in Logback.

By 
Hubert Klein Ikkink
·
Aug. 27, 15 · Code Snippet
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
6.0K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

When we use Logback as a SLF4J API implementation in our code we can have our logging output sent     to our console. By default the standard output is used to display the logging output. We can alter the configuration and have the logging output for the console send to standard error. This can be useful when we use a framework that uses the standard output for communication and we still want to see logging from our application on the console. We set the property target for the ConsoleAppender to the value System.err instead of the default System.out.

The following sample Logback configuration in Groovy send the logging output to the console and standard error:

appender("SystemErr", ConsoleAppender) {
    // Enable coloured output.
    withJansi = true

    encoder(PatternLayoutEncoder) {
        pattern = "%blue(%-5level) %green(%logger{35}) - %msg %n"
    }

    // Redirect output to the System.err.
    target = 'System.err'

}

root(DEBUG, ["SystemErr"])

If we want to use the XML format we get the following configuration:

<?xml version="1.0" encoding="UTF-8"?>
01.
<configuration>
02.

03.
<appender name="SystemErr"
04.
class="ch.qos.logback.core.ConsoleAppender"
05.
target="System.err"
06.
withJansi="true">
07.

08.
<encoder>
09.
<pattern>%blue(%-5level) %green(%logger{35}) - %msg %n</pattern>
10.
</encoder>
11.

12.
</appender>
13.

14.
<root level="DEBUG">
15.
<appender-ref ref="SystemErr"/>
16.
</root>
17.

18.
</configuration>


Console (video game CLI) Log4j application Framework Groovy (programming language) XML Property (programming) API

Published at DZone with permission of Hubert Klein Ikkink. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • New ORM Framework for Kotlin
  • How To Build Web Service Using Spring Boot 2.x
  • How to Connect to Splunk Through Anypoint Studio in 10 Steps
  • Your Application Has an Unindexed Attack Surface. Do You Know What’s in It?

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook