Issue While Trying To Write File Using Console Log

Seven Stars

Issue While Trying To Write File Using Console Log

Hi,

 

Please find attached job design.

 

We are trying to print console log to the txt file. Here is the code which we have written in tJAva_1.

 

File fileobj = new File("D:/Talend/" + jobName + TalendDate.getDate("DDMMYYYY-HHmmss") +".txt");

PrintStream obj = new PrintStream(new BufferedOutputStream(new FileOutputStream(fileobj)));

System.setErr(obj);

System.setOut(obj);

 

This code is logging only error information to the text file, e.g. error thrown from stored procedure. No other information is getting logged in to the text file.

 

We are basically logging steps in our job using tJavaRow component. We are expecting information from  tJavaRow component to get written in to text file.

 

Here is the code which we have written in our tJavaRow component

System.out.println("Going to Process AgentId " + input_row.AgentID);


Accepted Solutions
Seven Stars

Re: Issue While Trying To Write File Using Console Log

Hi,

 

Issue is resolved now. I forget to add tLogRow that's why one no error came no log was getting printed.

 

Thanks for the help.


All Replies
Sixteen Stars

Re: Issue While Trying To Write File Using Console Log

Are you sure the Job is running? Can you show us your errors? I suspect that they are compilation errors, in which case you will not see any data as the job will not actually run.

 

I do something very similar to this, but I split the output to be written to two different files as well as keeping it in the console. I do this using a tLibraryLoad component to import the commons-io-2.4.jar and then use the code below...

 

java.io.File outputFile = new java.io.File("c:/temp/output.txt");
java.io.FileOutputStream fosOut = new java.io.FileOutputStream(outputFile);

org.apache.commons.io.output.TeeOutputStream myOut = new org.apache.commons.io.output.TeeOutputStream(System.out, fosOut);
java.io.PrintStream psOut = new java.io.PrintStream(myOut, true); //true - auto-flush after println

java.io.File errorFile = new java.io.File("c:/temp/error.txt");
java.io.FileOutputStream fosErr = new java.io.FileOutputStream(errorFile);

org.apache.commons.io.output.TeeOutputStream myErr=new org.apache.commons.io.output.TeeOutputStream(System.err, fosErr);
java.io.PrintStream psErr = new java.io.PrintStream(myErr, true); //true - auto-flush after println

System.setOut(psOut);
System.setErr(psErr);

Re: Issue While Trying To Write File Using Console Log

Hi Tarunjit,

 

what is the issue ? Asuming you get an empty file log file ?

 

a)

May you forget to call a close on your BufferedOutPutStream ?

Consider to put a reference to you BufferedOutPutStream to the globalMap and call it with close()  at the end of the job.

 

b)

 Use your PrintStream with the fileObj instead of the BufferedOutputStream

 

BR  Bp

Seven Stars

Re: Issue While Trying To Write File Using Console Log

Hi,

 

Issue is resolved now. I forget to add tLogRow that's why one no error came no log was getting printed.

 

Thanks for the help.