Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to redirect all output of my console to a file ?

Hi everyone , 
Someon can help me plz , I need to redirect all output of my console ( create by Sys.output from tJava) to a file at the end of my process.
I want to see the log in my console too.
Is it possible ?
Labels (3)
10 Replies
Anonymous
Not applicable
Author

Hi,
You can achieve this by goin to the job properties and in Stats&logs section, define the file output path.
Hope this helps!!
Let me know if you need any more info on this.
Thanks,
Subarna
Anonymous
Not applicable
Author

You can't do this by editing Talend config I'm afraid. But you can do this with a little Java code in a tJava component at the beginning of your Job.
Below is a bit of code I use to send the output to a file called output.txt on my e: drive
java.io.File outputFile = new java.io.File("e:/output.txt");
System.setOut(new java.io.PrintStream(new java.io.FileOutputStream(outputFile, true), true));
Anonymous
Not applicable
Author

Hi,
Here is a custom component tRedirectOutput which redirect the log message printed on the console to a log file, and then read the header information from the log file and extract the session id.
Please see the related forum:http://community.talend.com:80/t5/Deployment/resolved-save-output-in-run-window-to-txt-file/m-p/8414...
Best regards
Sabrina
Anonymous
Not applicable
Author

Hi everybody ,
 @ xdshi , It appears that the componement not compatible with TOS 5.6
@ subarna3103 I did it  before post my squestion, but not work for me.
Anonymous
Not applicable
Author

Hi,
Have you tried this code in tJava?
java.io.File file = new java.io.File("/temp/mylogfile_test.txt");

java.io.PrintStream ps = new java.io.PrintStream(new java.io.FileOutputStream(file));
System.setOut(ps);


Best regards
Sabrina
Anonymous
Not applicable
Author

Hi   xdshi
Yes I used this code , but the problem it's that i have the log in myfile but i can't see it in console.
there is'nt solution include log in file + log on console ?
Jcs19
Creator II
Creator II

EDIT :  OH! try to use  System.out.println
DarinAfni
Contributor III
Contributor III

@Richard Hall​ this was very useful for me still 5 years later. If I'm doing this as part of the tPreJob section and I want to email the contents of this "log file" I'm writing console output to later on - how do I close the FileOutputStream for outputFile in another tJava in tPostJob ?

Anonymous
Not applicable
Author

I've always been lazy when using this code and have let the JVM closing close everything. Not ideal, but it works 🙂

What you could try is breaking the above code up onto several statements, then using the globalMap to store a reference to the FileOutputStream. Then in a tPostJob use the globalMap to get a reference to the FileOutputStream in another tJava, then close it there. After that tJava, use a tSendMail to send the file. It would be interesting to see if this works