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
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

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
  • Wrapping Mule4 — Secure Properties with TornadoFx

Trending

  • Selecting the Right Automated Tests
  • What Is Kubernetes RBAC and Why Do You Need It?
  • Top 7 Best Practices DevSecOps Team Must Implement in the CI/CD Process
  • How To Verify Database Connection From a Spring Boot Application
  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.

Hubert Klein Ikkink user avatar by
Hubert Klein Ikkink
·
Aug. 27, 15 · Code Snippet
Like (3)
Save
Tweet
Share
4.70K 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, DZone MVB. 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
  • Wrapping Mule4 — Secure Properties with TornadoFx

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: