Skip to Content

Standard JAVA Output


In JAVA programming, standard output(System.out) is frequently used for
tracing and debugging purpose.  The standard JAVA output prints the
information to the console, but in some particular scenes, we may hope it will
print the information to a certain file.

Also, a lots of beginners will wonder how to get the output information of the
standard JAVA output in server-side JAVA application such as EJB. That’s why
this weblog comes out.


Standard Output in Plain JAVA


In plain JAVA code, you can reassign the standard output stream to a file.

File file = new File(“c:
PrintConsole.txt”);
PrintStream printStream = new PrintStream(file);
System.setOut(printStream);
System.out.println(“Hello World!”);
System.out.flush();

The string “Hello World!” will be in the file c:\PrintConsole.txt.


Standard Output in EJB


For certain reasons, usage of System.setOut method in EJBs deployed onto the
SAP J2EE Engine will cause exceptions. Thus, we can only use other ways to get
standard output information. One is reassign the standard output to the default
trace file, the other is reassign the standard output to a specified file.

P.S: During configuring of JAVA Visual Administrator of WAS 6.40, I strongly recommend
you to put the console window which you start the VA right beside the VA
windows. The Log Configurator and Log Viewer service of VA is not implemented so
good that JAVA Exceptions will be frequently threw out. When you found this in
console window, quit the VA, restart it, and then continue the progress from the
step the exception was threw.

Caution: You would only turn on tracing of Standard JAVA Output if
your java code has some problems and you want to get the running status of the
code, after that, you should turn off the tracing of Standard JAVA Output.


I. Reassign Standard JAVA Output to the Default Trace File


    1. Operations in Log Configurator



     image
     

  • Open Visual Administrator.
  • Click the “Log Configurator” node under Cluster->Server->Services.
  • Select the “Locations” tab.
  • In the “Log Controllers” pane, select the “out” node under Root
    Location->System.
  • In the right pane, choose the “Info” for severity.
  • Save the change by clicking the save button.

    1. Operations in Log Viewer



     


II. Reassign Standard JAVA Output to A Specified File


    1. Operations in ConfigTool



     

  1. Open the ConfigTool.

Switch to configuration editor mode by clicking the
          image
          button.

    1. Navigate to cluster_data->server->cfg->kernel.

Switch to edit mode by clicking the
          image
          button.

    1. Double click on the “Propertysheet LogManager” node to change the
      Log properties.
    2. Change the property “ForceSingleTraceFile” from default “YES” to
      “NO”, and click “Apply custom” button.
    1. Operations in Log Configurator



     

  1. Open Visual Administrator.
  2. Click the “Log Configurator” node under Cluster->Server->Services.
  3. Switch to advanced mode by clicking the “To advanced mode” button.
  4. Create a destionation.
      1. Choose Destinations Tab.
      2. Ceate a new destination by clicking “New” button in the
        right pane, a popup dialog will appear.
      3. Fill the “Name:” field for destination name, such as “TestLogDestination”.
      4. Choose the “FileLog” as the “Type”.
      5. Fill the “File Name Pattern:” for log file path and file
        name, such as “/tmp/log.txt”.
      6. Fill the “Maximum File Size:” for log file size, such as “1048576”.
      7. Fill the “Number Of Files:” for number of log files, such as
        “2”, then you’ll find log.0.txt and log.1.txt under path /tmp.
      8. After all fields have been filled, click button “OK”.
      9. Fill the “Encoding:” for log file encoding, such as “UTF-8”.
      10. Add a formatter.
          1. Click the “Add” button beside the Formatter pane,
            the Add Formatter popup dialog will appear.
          2. Click the “Anonymous” button, choose “List
            Formatter” in the popup dialog and click “OK” button.
          3. The “Anonymous[ListFormatter] item will be in the
            list, choose it and click “Select” button.

Save by click image button.
                    


              image
              

      1. Add the new created destination to Locations.
      1. Choose “Locations” Tab and click the “Add” button beside the “Destinations” pane, a popup dialog will appear.
      2. Select the destination that we’ve just created and click “Select” button.

    Save by click image button.
                   

    Now we’ve finished everything we should do in Log Configurator.


              image
         


         

      1. Operations in LogViewer



         

    1. Click the “LogViewer” node under Cluster->Server->Services.
    2. In the area below runtime tab, right click “Cluster” node and choose
      “Add a log file”, “Add monitorable file” popup dialog will appear.

    In the “Enter a file:” field, enter the path and file name of your
              destination log file. We enter “\tmp\log.” for example.

    Wildcard characters can be use here. “*” stands for any string and “…”
    stands for cross multiple directories.

    The path of your log file must be “monitorable”, that means, the path
    should be added to “Logviewer_MonitorablePath” property under
    “Properties” tab of “LogViewer” service. The monitorable paths should be
    seperated using ‘;’.

      1. Click the “Show File List” button and the log files would appear in
        the right pane. Choose it and click “Add” button below.


                   image
              


    To report this post you need to login first.

    6 Comments

    You must be Logged on to comment or reply to a post.

    1. Theo Droste

      Hi, <br/><br/>When I follow your tutorial I get this (Apparantly the server changed the name from .\log\eee.0.log to .\log\eee.log.0)<br/>Is this a bug in NW?)<br/><br/><!LOGHEADER[START]/><br/><!HELP[Manual modification of the header may cause parsing problem!]/><br/><!LOGGINGVERSION[1.5.3.7185 – 630]/><br/><!NAME[.\log\eee.log]/><br/><!PATTERN[eee.log]/><br/><!FORMATTER[com.sap.tc.logging.ListFormatter]/><br/><!ENCODING[Cp1252]/><br/><!FILESET[0, 3, 100000]/><br/><!PREVIOUSFILE[eee.2.log]/><br/><!NEXTFILE[eee.1.log]/><br/><!LOGHEADER[END]/><br/>#1.5#0014225E5FF1001F000001CD000006EC0004201619A731BF#1161179198666#com.sap.tc.logging.reader.LocalBuffer##com.sap.tc.logging.reader.LocalBuffer.#Administrator#781##PC05717.publishers_LDI_13780950#Administrator#b06570805eae11db822b0014225e5ff1#SAPEngine_Application_Thread[impl:3]_2##0#0#Path#1#/System/Logging#Java#7D4E986F-B684-4942-B3E7-FEDA3AB57100##Error in opening File(.
      log
      eee.log.0)!##<br/>#1.5#0014225E5FF1001F000001CE000006EC0004201619A73B55#1161179198666#com.sap.tc.logging.reader.LocalBuffer##com.sap.tc.logging.reader.LocalBuffer#Administrator#781##PC05717.publishers_LDI_13780950#Administrator#b06570805eae11db822b0014225e5ff1#SAPEngine_Application_Thread[impl:3]_2##0#0#Path##Java###Error in opening File(.
      log
      eee.log.0)! <br/>[EXCEPTION]<br/> #1#com.sap.tc.logging.exceptions.FileOpenException: Error in opening File(.
      log
      eee.log.0)!     at com.sap.tc.logging.reader.ReadableLog.createReadableLog(ReadableLog.java:148)

      (0) 
      1. YiNing Mao Post author
        I haven’t seen this kind of exception before.
        Tell me more details, how do you maintain the “Pattern:” filed in destination?
        Are there \log\eee.0.log, \log\eee.1.log in your operation system?
        Can you monitor eee.log in the logViewer?
        Is the \log\ path one of the monitorable paths?
        (0) 

    Leave a Reply