Printing out Context and Dumping the Output in Talend

Printing out the context

Getting ready

Open the jo_cook_ch10_0080_tContextDump job.

How to do it…

The steps for printing out the context are as follows:

  • Open the Context tab, and you will see a set of context variables.

talend 20

  • Drag a tContextDump component from the palette.
  • Attach a tLogRow
  • Run the job.

How it works…

tContextDump simply dumps all the context variables defined within the job into a flow that can then be logged via tLogRow.

There’s more…

This component is most useful when running code that has been deployed to a server, because the log information is usually stored in a file. This allows us to check the values of the context variables at the time of execution that would otherwise be hidden from us. This is invaluable for debugging a deployed process that has failed.


Often, contexts contain sensitive information, such as user names and passwords to system resources. If you do not want these to be shown, then ensure that when you dump the data, you tick the Hide Password option.

Dumping the console output to a file from within a job

This recipe shows how you can dump all logging data to a file, while still running the job in the Studio. It is particularly useful when debugging large data sets.

Getting ready

Open the jo_cook_ch10_0090_consoleToFile job.

How to do it…

The steps for dumping console output to a file from within a job are as follows:

  • Run the job and view the console output.
  • Add the following code to tJava_1:
// redirect the console output to a file from within studio System.setOut(new java.io.PrintStream(new java.io.BufferedOutputStream(new java.io.FileOutputStream(context.cookbookData+"outputData/chapter 10/chapter10_jo_0090_consoleOut.txt"))));
  • Run the job. You will see only the job’s start and end messages.
  • Open the file in the cookbook data directory under output/chapter10 named chapter10_jo_ 0090_ consoleOut.txt. You will see that the logging information has been copied to the file, as shown in the following screenshot:

talend 21

How it works…

When the Java statement is added to tJava_1, it causes virtually everything that is normally written to the console (System.out.println(), tLogRow) to be directed to a file instead.

There’s more…

The benefit of this technique is that debugging large data sets can be performed in the Studio without the massive performance hit of logging to console and without the need to export the job each time you wish to run it.

It also has the added benefit over writing logging information via a fileOutput component, in that it retains the formatting of tLogRow/tJavaRow and tJava as if it was being output to the console, making the flow of the job logging information easier to understand.





0 Responses on Printing out Context and Dumping the Output in Talend"

Leave a Message

Your email address will not be published. Required fields are marked *

Copy Rights Reserved © Mindmajix.com All rights reserved. Disclaimer.