Hurry! 20% Off Ends SoonRegister Now

Printing out Context and Dumping the Output in Talend

Printing out the context

Getting ready

Open the jo_cook_ch10_0080_tContextDump job.

Related Page:: Managing Talend Context Variables

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.
  • 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.

Tip

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.

MindMajix Youtube Channel

MindMajix Talend Training course is designed to make you an expert in developing ETL solutions using Talend platform. Start Learning!

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:

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.

Explore TALEND Sample Resumes! Download & Edit, Get Noticed by Top Employers!Download Now!

 

Job Support Program

Online Work Support for your on-job roles.

jobservice

Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:

  • Pay Per Hour
  • Pay Per Week
  • Monthly
Learn MoreGet Job Support
Course Schedule
NameDates
Talend TrainingDec 24 to Jan 08View Details
Talend TrainingDec 28 to Jan 12View Details
Talend TrainingDec 31 to Jan 15View Details
Talend TrainingJan 04 to Jan 19View Details
Last updated: 03 Apr 2023
About Author

Ravindra Savaram is a Technical Lead at Mindmajix.com. His passion lies in writing articles on the most popular IT platforms including Machine learning, DevOps, Data Science, Artificial Intelligence, RPA, Deep Learning, and so on. You can stay up to date on all these technologies by following him on LinkedIn and Twitter.

read less