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

  • Home
  • SEARCH
  • 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 8374091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:50:39+00:00 2026-06-09T14:50:39+00:00

I need to monitor console output in Java, I have tried several different ways

  • 0

I need to monitor console output in Java, I have tried several different ways of retrieving the output as it is streamed, but I fell into a few pitfalls (looping the same output, only one part of output being captured, losing output) and have decided to go about it a different way.

I am developing a Java plugin for a server of the popular game, Minecraft, and I need to be able to monitor console output from other plugins.


I think a good way to do this is by redirecting console output to file, and then set up a recurring async task that checks the file, carries out anything it needs to do, and then clears the file for more input. I think I can do this with a simple use of System.setOut(PrintStream stream); and one of the many guides I can find on Google.

But there is a problem, and that is why I am asking here today. I need console output to stay on the console like normal, hence “mirroring”. I cannot edit any of the plugins to output somewhere else, it needs to be from what my Java plugin can do and that only. Sure, maybe on every scheduled check on the file I could reprint it all back to the console but that would result in blocks being printed at a time, which would not be ideal. I do hope this is possible. Thank you!

EDIT: I don’t think I explained fully. “plugins”‘s classes are run by the program that I am developing for. I cannot change how classes are run and I cannot change how other plugins print to console.
I also do not want to direct console output to files for logging, that idea is only to keep it in a temporary place while it is parsed. Ideally, I need to pass each line of console output to a function (parseString(String line)) which carries out operations depending on the contents of the line. Also, I don’t understand how I can read stream contents line-by-line properly, so if someone has any idea on how to, please let me know. 🙂

  • 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-06-09T14:50:40+00:00Added an answer on June 9, 2026 at 2:50 pm

    Capture System.out before changing it, and use TeeOutputStream:

    OutputStream myCaptureStream = ...;
    PrintStream original = System.out;
    OutptStream outputtee = new TeeOutputStream(originalOut, myCaptureStream);
    PrintStream printTee = new PrintStream(outputTee);
    System.setOut(printTee);
    

    Convert output stream (myCaptureStream) to an input stream

    • Use Java standard library PipedOutputStream: new PipedOutputStream; read carefully – you’ll need your reader running on another thread.
    • Convert the input stream to a Reader,
    • and that to a BufferedReader.

    BufferedReader gives you a readLine method.

    Pseudo code:

    // Feed myCaptureStream to TeeOutputStream
    OutputStream myCaptureStream = new PipedOutputStream();
    
    // Prepare to capture data being written to that output stream
    InputStream myCaptureAsInputStream = new PipedInputStream(myCaptureStream);
    Reader myCaptureReader = new InputStreamReader(myCaptureAsInputStream);
    BufferedReader myCaptureBuffered = new BufferedReader(myCaptureReader, 1024);
    
    // This must run on separate reader thread; in spin loop:
    myCaptureBuffer.readLine
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to monitor HTTP traffic in my dev env which is PHP/Apache/Windows. But
I need to monitor the network traffic in Android, but I don't know how
I have a project where I need to monitor changes in a 3rd party
I have a VB app that I need to monitor while it is running.
I need to monitor a system with AIX 5.3, but can't find a good
I need to monitor network bandwidth between two nodes. I have full access to
I need to monitor several systems going thru stress testing. I want to make
I have a folder that contains multiple word documents. I need to monitor this
I need to have a FileSystemWatcher run in an infinite loop to monitor a
I have a need to monitor a subset of fields on a table and

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.