Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4339908
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:16:42+00:00 2026-05-21T11:16:42+00:00

I have some libraries that are calling System.out.println on me, I’d like to redirect

  • 0

I have some libraries that are calling System.out.println on me, I’d like to redirect them through log4j or commons logging. But in particular I’d like to keep the fully-qualified-classname so I know what component generated the logs.

Is there a nice, orderly way to accomplish this?


UPDATE: After accomplishing this I posted the code here:

http://www.bukisa.com/articles/487009_java-how-to-redirect-stderr-and-stdout-to-commons-logging-with-the-calling-class

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T11:16:43+00:00Added an answer on May 21, 2026 at 11:16 am

    The only way I can think of would be to write your own PrintStream implementation which created a stack trace when the println method was called, in order to work out the class name. It would be pretty horrible, but it should work… proof of concept sample code:

    import java.io.*;
    
    class TracingPrintStream extends PrintStream {
      public TracingPrintStream(PrintStream original) {
        super(original);
      }
    
      // You'd want to override other methods too, of course.
      @Override
      public void println(String line) {
        StackTraceElement[] stack = Thread.currentThread().getStackTrace();
        // Element 0 is getStackTrace
        // Element 1 is println
        // Element 2 is the caller
        StackTraceElement caller = stack[2];
        super.println(caller.getClassName() + ": " + line);
      }
    }
    
    public class Test {
      public static void main(String[] args) throws Exception {
        System.setOut(new TracingPrintStream(System.out));
        System.out.println("Sample line");
      }
    }
    

    (In your code you would make it log to log4j instead of course… or possibly as well.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found some libraries or web services in PHP that does the job.
I have inherited a project that has class libraries written in VB.NET, some of
I have some classes layed out like this class A { public virtual void
I do have a simple cmake project (on linux) that loads some libraries from
I have recently come across a situation where code is dynamically loading some libraries,
I have some UI in VB 2005 that looks great in XP Style, but
We have some input data that sometimes appears with &nbsp characters on the end.
I have some code like this in a winforms app I was writing to
System.Collections.Concurrent has some new collections that work very well in multithreaded environments. However, they
Status Quo For our customer we are developing some libraries and applications that run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.