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
Over 2 million developers have joined DZone.
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
  • Building a Reusable Framework to Standardize API Ingestion in an On-Prem Lakehouse

Trending

  • Every Cache Miss Is a Tiny Tax on Your Performance
  • Building a Zero-Cost Approval Workflow With AWS Lambda Durable Functions
  • AI Agents in Java: Architecting Intelligent Health Data Systems
  • Feature Flag Debt: Performance Impact in Enterprise Applications
  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 user avatar
Hubert Klein Ikkink
·
Aug. 27, 15 · Code Snippet
Likes (3)
Comment
Save
Tweet
Share
5.8K Views

Join the DZone community and get the full member experience.

Join For Free

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
  • Building a Reusable Framework to Standardize API Ingestion in an On-Prem Lakehouse

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • 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