Results 1 to 3 of 3
  1. #1
    jhyuk is offline Member
    Join Date
    Nov 2009
    Posts
    2
    Rep Power
    0

    Default Logging Standard output to a file

    I'm not sure if this counts as an advanced Java question, probably not.
    The issue is that I have a complex program with a lot of classes, which I did not write the whole thing.

    It currently prints out some debugging information from various classes to standard output.

    But the problem is that there are multiple users of the application and it would be easier if there was a log file for support questions from users.

    I was wondering if there was a way to log(redirect) all of the standard output to a file, since it would be a hassle to find all of the standard output and change it to use something like the java.util.logging api.

    The current program is a Java Application(jar file) launched through Java WebStart

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    In the main method do

    Java Code:
    FileOutputStream fos = new FileOutputStream(<logfileNameWithFullPath>, true);
    PrintStream ps = new PrintStream(fos);
    System.setOut(ps);

  3. #3
    jhyuk is offline Member
    Join Date
    Nov 2009
    Posts
    2
    Rep Power
    0

    Default

    thanks a lot
    worked like a charm.

    for anyone who's interested, could also be a good idea to add

    Java Code:
    System.setErr(ps);

Similar Threads

  1. problem with output of jar file
    By nishant.4545 in forum Advanced Java
    Replies: 2
    Last Post: 07-04-2009, 05:00 PM
  2. No output to file
    By shiva in forum Java Servlet
    Replies: 0
    Last Post: 04-24-2009, 03:06 PM
  3. Output to a text file
    By sfe23 in forum New To Java
    Replies: 4
    Last Post: 03-26-2009, 11:44 PM
  4. Java logging - log file location for FileHandler
    By kfir.wolfson@gmail.com in forum Advanced Java
    Replies: 2
    Last Post: 03-24-2009, 09:22 AM
  5. Replies: 7
    Last Post: 11-19-2008, 03:09 PM

Posting Permissions

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