Skip to main content Skip to complementary content
Close announcements banner

Activating and configuring Log4j

Talend Studio includes the Apache logging utility Log4j to provide logging at runtime. You can enable or disable Log4j loggers in components and customize the Log4j configuration globally for the project.

Information noteWarning: Following the Log4j2 security issue (CVE-2021-44228), make sure to disable Log4j loggers when you run Spark Batch and Spark Streaming Jobs with Dataproc 2.x and onwards, Azure Synapse and HD Insight 4.0 distributions.

To avoid any Job failure, clear the Activate log4j in components check box from the Log4j view in File > Edit Project Properties > Project Settings or clear the log4jLevel check box from the Advanced settings view of your Spark Job.

Procedure

  1. On the toolbar of the Talend Studio main window, click Project settings or click File > Edit Project Properties from the menu bar to open the Project Settings dialog box.
  2. In the tree view of the dialog box, click the Log4j node to open the Log4j view.
    Log4j view.
  3. Select the Activate log4j in components check box to activate the Log4j feature.

    By default, the Log4j feature is activated and Log4j 2 is enabled when a project is created.

    When a project is imported from Talend 7.2 or an earlier version, which only supports Log4j 1, the deprecated Log4j 1 is selected from the Log4j version drop-down list by default. All POM files for the project will be synchronized when you change the Log4j version.

    Information noteNote: If you need to deploy your Jobs to Talend Cloud, the use of Log4j 2 requires Talend Remote Engine 2.8.1 or higher.
  4. If needed, change the global Log4j configuration by modifying the XML instructions in the Log4j template area.
    For example, to configure the root logger for Log4j 2 to output all debug or higher messages, go to the Loggers section and set the value of the level attribute of the root node to debug.

    If you have installed the 8.0 R2022-09 Talend Studio monthly update or a later one provided by Talend, the Log4j 2 MDC (Mapped Diagnostic Context) is populated with key-value pairs. These extra log attributes help you easily identify the thread in which log data is generated when all log messages from multiple threads are written into a single file. For more information about Log4j 2 MDC, see Log4j 2 API - Thread Context.

    Example logs.

    To include all extra log attributes when writing logs, add %X in the PatternLayout section.

    <PatternLayout pattern="[%-5level] %d{HH:mm:ss} %logger{36}- %X %msg%n" />

    To include specific log attributes when writing logs, add %X{key} %X{key2} ... %X{keyN} in the PatternLayout section, where {keyN} is the key of the corresponding log attribute. You can also use characters like commas to separate attributes to easily identify them. The following example includes the _pid and _startTimestamp attributes when writing logs.

    <PatternLayout pattern="[%-5level] %d{HH:mm:ss} %logger{36}- %X{_pid}, %X{_startTimestamp} %msg%n" />

    For more information about Log4j 2 configuration, see Configuring with XML.

    For more information about Log4j 1 configuration, see Log4jXmlFormat.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!