Results 1 to 3 of 3
  1. #1
    ZioBafio is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default Redirecting System.err on two output

    Hi All!

    I need to redirect System.err on two output, in order to keep track of exception both on a file and on console

    at this moment, I only redirect errors output on a file:

    Java Code:
    System.setErr(out);
    where out is a PrintStream

    when an exception occours, I'd like to print a video message also

    the best result would be to print the entire stack trace, but even writing "ERROR" would be fine

    could anyone help me?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,271
    Blog Entries
    7
    Rep Power
    24

    Default

    I think the simplest solution is to implement a 'tee' OutputStream like this:

    Java Code:
    public class TeeOutputStream extends OutputStream {
       private OutputStream out1;
       private OutputStream out2;
    
       public TeeOutputStream(OutputStream out1, OutputStream out2) {
          this.out1= out1;
          this.out2= out2;
       }
    
       public void write(int b) throws IOException {
          out1.write(b);
          out2.write(b);
       }
    }
    Pass two OutputStreams to its constructor and all output writen to the TeeOutputStream will be written to the two encapsulated OutputStreams.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  3. #3
    ZioBafio is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

Similar Threads

  1. Redirecting output of java program to file
    By dewitrydan in forum New To Java
    Replies: 4
    Last Post: 11-17-2010, 07:58 AM
  2. Problem while redirecting script output to a file using java
    By umapathy_sekar in forum Advanced Java
    Replies: 4
    Last Post: 11-09-2010, 10:33 AM
  3. Save the output from system.out.println into a file
    By Iskatel in forum Advanced Java
    Replies: 5
    Last Post: 10-05-2010, 02:52 PM
  4. Need help in redirecting to a url
    By umapathy_sekar in forum Advanced Java
    Replies: 1
    Last Post: 09-27-2010, 12:52 PM
  5. Redirecting output at Thread level
    By beezerbutt in forum Advanced Java
    Replies: 8
    Last Post: 02-15-2009, 12:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •