Changing System.out to a file stream using System.setOut - Weblogic

This is a discussion on Changing System.out to a file stream using System.setOut - Weblogic ; Hi, I am trying to change the default System.out to output to a File Stream using using the following code. This code runs during the app. server startup. ********************START OF CODE SNIPPET************************************ // fileoutput stream for writing to the specified ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Changing System.out to a file stream using System.setOut

  1. Changing System.out to a file stream using System.setOut


    Hi,

    I am trying to change the default System.out to output to a File Stream using
    using the following code. This code runs during the app. server startup.

    ********************START OF CODE SNIPPET************************************

    // fileoutput stream for writing to the specified log file
    FileOutputStream outFileStream = new FileOutputStream(stdOut);

    // Buffered output Stream wrapper for the file output stream
    // buffer size of 1 Kb

    BufferedOutputStream bufferOutStream =
    new BufferedOutputStream(outFileStream, 1024);

    // Wrapping the buffered stream to be used with
    // Print stream
    PrintStream printOutStream = new PrintStream(bufferOutStream);

    // setting the print stream object created as the
    // System.out
    System.setOut(printOutStream);

    ********************** END OF CODE SNIPPET************************************


    Please let me know any potential probelms of using System.out
    in EJBs. I am using WebLogic 8.1 SP1 as app. server.

    TIA,
    Ram Kishore.



  2. Re: Changing System.out to a file stream using System.setOut

    I wouldn't suggest doing this. Anyone who looks at this code in a few
    years will see System.out.println(...) and will be wondering why it
    doesn't appear on their screen.

    I'd suggest using a logging service instead. There's plenty of choices:
    WLS logging, JDK logging, log4j etc

    -- Rob

    Ram Kishore wrote:
    > Hi,
    >
    > I am trying to change the default System.out to output to a File Stream using
    > using the following code. This code runs during the app. server startup.
    >
    > ********************START OF CODE SNIPPET************************************
    >
    > // fileoutput stream for writing to the specified log file
    > FileOutputStream outFileStream = new FileOutputStream(stdOut);
    >
    > // Buffered output Stream wrapper for the file output stream
    > // buffer size of 1 Kb
    >
    > BufferedOutputStream bufferOutStream =
    > new BufferedOutputStream(outFileStream, 1024);
    >
    > // Wrapping the buffered stream to be used with
    > // Print stream
    > PrintStream printOutStream = new PrintStream(bufferOutStream);
    >
    > // setting the print stream object created as the
    > // System.out
    > System.setOut(printOutStream);
    >
    > ********************** END OF CODE SNIPPET************************************
    >
    >
    > Please let me know any potential probelms of using System.out
    > in EJBs. I am using WebLogic 8.1 SP1 as app. server.
    >
    > TIA,
    > Ram Kishore.
    >
    >



+ Reply to Thread