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 6085677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:39:57+00:00 2026-05-23T11:39:57+00:00

our project uses System.out.println() or System.err.println() to output debugging message. Now we want to

  • 0

our project uses System.out.println() or System.err.println() to output debugging message. Now we want to use log4j to direct these output to log files not just console. To avoid impact or risk, we don’t want to do replace all “System.out.println()” with “logger.debug” but just want to maybe write several code to make these output redirect to log4j log files that is no code change in each class still using System.out.println() (we know this is bad practice but we don’t want to do global search and replace currently). Is it possible? Thanks.

  • 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-23T11:39:57+00:00Added an answer on May 23, 2026 at 11:39 am

    I guess it is possible, though it is definitely a bad idea. You should bite the bullet and replace all of the System.out.printXXx() and System.err.printXXx() calls.

    (You don’t have to do this in one big change, and you don’t have to do it using an automated search / replace … if these things make you feel uncomfortable.)


    You can change where those streams go by using System.setOut and System.setErr to point them to a log4j log file. However:

    • you may get problems with interleaving of output and/or log file truncation, depending on exactly how the log4j appenders are implemented
    • you won’t get log4j time stamps, etc
    • you won’t have the ability to control the logging via the log4j configs, because your redirection is going behind the back of log4j
    • log4j logfile rotation won’t work properly

    A more complicated alternative would to create special OutputStream object to intercept the output and turn it into calls to a log4j Logger. But this also would have problems too:

    • it could be tricky figuring out where each “console log message” ends, especially if you want multiple lines of console output to be treated as one log event
    • you’ll only have limited log4j configurability, because all “console log messages” will go through a single Logger (or maybe one for out and one for err)
    • performance will be a bigger and less tractable issue than with normal log4j logging.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm in a embedded led measuring system project now. It uses ARM & linux,
Our project currently uses Crystal Reports for Visual Studio 2008. We need to upgrade
I have an old project at our company that uses shell scripting a lot.
Our project constitutes of many modules (e.g. a HR management system containing modules like
In our project we have requirement that, after receiving sms message from third party
Our project uses an LDAP repository for storing users. In production this will be
I am starting a new c++ project and I want to use Boost.Build /
ORIGINAL QUESTION Our application uses CSocket which requires the message pump to be running
Our current project at work is a new MVC web site that will use
Our web project uses spring3, Jpa (hibernate). To save CRUD and other commonly used

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.