July 30, 2023

tLogCatcher – Docs for ESB 7.x

tLogCatcher

Operates as a log function triggered by one of the three: Java
exception, tDie or tWarn, to collect and transfer log
data.

Both the tDie and tWarn
components are closely related to the tLogCatcher
component.They generally make sense when used alongside a tLogCatcher component in order for the log data collected to be encapsulated
and passed on to the output defined.

Fetches set fields and messages from Java Exception, tDie and/or tWarn and passes them on to the next component.

tLogCatcher Standard properties

These properties are used to configure tLogCatcher running in the Standard Job framework.

The Standard
tLogCatcher component belongs to the Logs & Errors family.

The component in this framework is available in all Talend
products
.

Basic settings

Schema and Edit
Schema

A schema is a row description, it defines the fields to be processed
and passed on to the next component.

The schema of this component is read-only. It describes the properties
of the log data. You can click the […] button next to Edit
schema
to view the predefined schema which contains the
following fields:

  • moment: the time when the
    message is caught.

  • pid: the process ID of the
    Job.

  • root_pid: the root process
    ID.

  • father_pid: the father
    process ID.

  • project: the name of the
    project.

  • job: the name of the
    Job.

  • context: the context used to
    run the Job.

  • priority: the priority level
    of the message.

  • type: the type of the
    message.

  • origin: the name of the
    component that triggers the message.

  • message: the message
    content.

  • code: the error code
    level.

Catch Java Exception

Select this check box to trigger the tCatch function when a Java Exception occurs in the
Job.

Catch tDie

Select this check box to trigger the tCatch function when a tDie component is called in a Job.

Catch tWarn

Select this check box to trigger the tCatch function when a tWarn component is called in a Job.

Global Variables

Global Variables

ERROR_MESSAGE: the error message generated by the
component when an error occurs. This is an After variable and it returns a string. This
variable functions only if the Die on error check box is
cleared, if the component has this check box.

A Flow variable functions during the execution of a component while an After variable
functions after the execution of the component.

To fill up a field or expression with a variable, press Ctrl +
Space
to access the variable list and choose the variable to use from it.

For further information about variables, see
Talend Studio

User Guide.

Usage

Usage rule

This component is usually used as the start component of a secondary
Job which is automatically triggered at the end of the main Job.

Catching messages triggered by a tWarn component

This example shows you how to use the tLogCatcher component to catch the messages triggered by a tWarn component.

Creating a Job for catching messages triggered by a tWarn component

Create a Job to trigger some messages using the tWarn component, then catch the messages using the tLogCatcher component and display the messages on the
console.

tLogCatcher_1.png

  1. Create a new Job and add a tRowGenerator component, a tWarn
    component, a tLogCatcher component, and a tLogRow component by typing their names in the design
    workspace or dropping them from the Palette.
  2. Link the tRowGenerator component to
    the tWarn component using a Row > Main connection.
  3. Link the tLogCatcher component to the
    tLogRow component using a Row > Main connection.

Configuring the Job for catching messages triggered by the tWarn component

Configure the components used in the Job that catches the
messages triggered by the tWarn component and
then displays the messages on the console.

  1. Double-click the tRowGenerator
    component to open its row generator editor.

    tLogCatcher_2.png

  2. Define the schema by adding one column id of Integer type, and select the predefined function Numeric.sequence(String,int,int) in the Functions column.
  3. Enter the number of records to be generated in the Number of Rows for RowGenerator field, 3 in this example. When done, click OK to close the dialog box.
  4. Double-click the tWarn component to
    open its Basic settings view.

    tLogCatcher_3.png

  5. Select Info from the Priority drop-down list.
  6. In the Warn message field, enter the
    message to be triggered when a new record is generated, a
    new record is generated
    in this example.
  7. Double-click the tLogCatcher component
    to open its Basic settings view.

    tLogCatcher_4.png

  8. Select the Catch tWarn check box to
    catch the messages triggered by the tWarn
    component.
  9. Double-click the tLogRow component to
    open its Basic settings view, and then select
    Table (print values in cells of a table) in the
    Mode area for better readability of the
    result.

Executing the Job to catch messages triggered by a tWarn component

After setting up the Job and configuring the components used in
the Job for catching messages triggered by the tWarn component, you can then execute the Job and verify the Job execution
result.

  1. Press Ctrl + S to save the Job.
  2. Press F6 to execute the Job.

    tLogCatcher_5.png

    As shown above, all messages triggered are collected and displayed on the
    console.

Catching the message triggered by a tDie component

This example shows you how to use the tLogCatcher component to catch the message triggered by a tDie component.

Creating a Job for catching the message triggered by a tDie component

Create a Job to trigger a message using the tDie component, then catch the message using the tLogCatcher component and display the message on the console.

tLogCatcher_6.png

  1. Create a new Job and add a tRowGenerator component, a tFileOutputDelimited component, a tDie component, a tJava component,
    a tLogCatcher component, and a tLogRow component by typing their names in the design
    workspace or dropping them from the Palette.
  2. Link the tRowGenerator component to
    the tFileOutputDelimited component using a
    Row > Main
    connection.
  3. Link the tFileOutputDelimited
    component to the tDie component using a Trigger > Run if
    connection.
  4. Link the tRowGenerator component to
    the tJava component using a Trigger > On Subjob Ok
    connection.
  5. Link the tLogCatcher component to the
    tLogRow component using a Row > Main connection.

Configuring the Job for catching the message triggered by the tDie component

Configure the components used in the Job that catches the message
triggered by the tDie component and then displays
the message on the console.

  1. Double-click the tRowGenerator
    component to open its row generator editor.

    tLogCatcher_7.png

  2. Define the schema by adding one column id of Integer type, and select the predefined function Numeric.sequence(String,int,int) in the Functions column.
  3. Enter the number of rows to be generated in the Number of Rows for RowGenerator field, 0 in this example. When done, click OK to close the dialog box.
  4. Double-click the tFileOutputDelimited
    component to open its Basic settings view, and in
    the File Name field, specify the path to the file
    that will hold the data to be generated.
  5. Click the If connection, and in the
    Condition field on the Basic settings view, specify the condition based on which the
    tDie component will be triggered. In this
    example, it is ((Integer)globalMap.get(“tRowGenerator_1_NB_LINE”)) <=0, which
    means the tDie component will be triggered when the
    number of rows to be generated is less than or equal to zero.
  6. Double-click the tDie component to
    open its Basic settings view, and in the Die message field, enter the message to be triggered
    before the Job is killed. In this example, it is no row
    generated
    .

    tLogCatcher_8.png

  7. Double-click the tJava component to
    open its Basic settings view, and in the Code field, enter

    Note that this message will be displayed only when the number of rows generated is
    greater than zero. In this example, the number of rows to be generated is 0, so the Job will be killed and this message will not
    be displayed.
  8. Double-click the tLogCatcher component
    to open its Basic settings view and select the
    Catch tDie check box to catch the message
    triggered by the tDie component.

    tLogCatcher_9.png

  9. Double-click the tLogRow component to
    open its Basic settings view, and then select
    Table (print values in cells of a table) in the
    Mode area for better readability of the
    result.

Executing the Job to catch the message triggered by the tDie component

After setting up the Job and configuring the components used in
the Job for catching the message triggered by the tDie component, you can then execute the Job and verify the Job execution
result.

  1. Press Ctrl + S to save the Job.
  2. Press F6 to execute the Job.

    tLogCatcher_10.png

    As shown above, the message triggered is collected and displayed on the
    console.
  3. Change the number of rows to be generated (10 for example) in the Number of Rows for
    RowGenerator
    field of the tRowGenerator component, save and execute the Job again to find a
    different result.

Document get from Talend https://help.talend.com
Thank you for watching.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x