Friday, September 27, 2013

How to redirect standard output to a file

Many times you need to get log details on external files which Talend is not able to redirect or catch using standard Log management, but you know many times error displays on Talend run console but is not caught in error connector. so here is sample code which you can use in your job to redirect error or run console messages to file.

just at the beginning of you job place tJava, and inside a tjava, redirect globally the standard output... insert this code (add buffering if you need):

-------------------------
java.io.File file = new java.io.File("C:/data/mylogfile_test.txt");
java.io.PrintStream ps = new java.io.PrintStream(new java.io.FileOutputStream(file));
System.setErr(ps);
System.setOut(ps);
-------------------------

3 comments:

  1. With above code used, I receive following message inside the file, when there is no error.
    [statistics] disconnected.

    Want to know how to get complete log trace from the console. The line which is displayed above, was not displayed on Talend console, but still it is there in the file ??

    Thanks
    Vaibhav

    ReplyDelete
  2. Hi Vaibhav,
    I have updated above code please use it will help to get errors to file.

    ReplyDelete

Contact Us

Name

Email *

Message *