Talend, How to export log in JSON Format?
      
      21/06/2023
      
      
      @ Saigon
      
      Talend
    
    Step 1: Go to File → Project Properties
  Step 2: Go to log4j section and Activate log4j in components (Log4j version: log4j2)
  In the Log4j template, use the following template.
<?xml version="1.0" encoding="UTF-8"?>
<Configuration >
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout  >
        <pattern>
          { "timestamp":"%d{ISO8601}{GMT+0}", "level":"%level", "category":"%c", "message":"%enc{%m}{JSON}" }%n
        </pattern>
      </PatternLayout>
    </Console>
  </Appenders>
  <Loggers>
    <Root level="INFO">
      <AppenderRef ref="Console" />
    </Root>
  </Loggers>
</Configuration>Step 3: Create tJava in Talend Job to export log
  - Basic settings code:
 
String message = "Hello World";
log.fatal(message);
log.error(message);
log.warn(message);
log.info(message);
log.debug(message);
log.trace(message);- Advanced settings code:
 
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;You then can RUN your talend job, the output should look like the following.
  References
- Configure PatternLayout, jmcollin92, 2021, May 24, https://stackoverflow.com/questions/29387007/does-log4j-support-json-format#comment119606534_37455869.
 - Handle special character in json log message, Nishan B, 2022, November 25, https://stackoverflow.com/questions/29387007/does-log4j-support-json-format#comment131629876_37455869.