Is there a way to use the log4j Talend instance to log in the Jobs?

Question

Which log4j logger instance should be used to log inside a Job?

 

Answer

The tJava component allows you to use the existing log instance of the Job, for example:

 

log.debug("DEBUG: Hello World");
log.info("INFO: Hello World");
log.warn("WARN: Hello World");
log.error("ERROR: Hello World");
Version history
Revision #:
6 of 6
Last update:
‎04-04-2019 01:30 AM
Updated by:
 
Comments
Six Stars

Using Talend Open Studio 6.3.0, I get the compilation error:

 

At least job "Test_Log4j" has a compile errors, please fix and export again.
Error Line: 1446
Detail Message: log cannot be resolved

 

when using tJava component and 

 

log.info("INFO: job started");

 

 

Moderator

Hello @tale103108 ,

Are you using a log4j component to create your logger object? You will look at the generated code to get the name of the object. once you have the object, you can send log messages to it directly in code by:
<logger_name>.info("this is an info message"); 

Best regards

Sabrina

Six Stars
I am using Talend Open Studio 6.3.0.

Are there log4j components in the free version? If so, what are they called?


Moderator

Hello @tale103108,

Talend Open Studio doesn't have option to enable log4j logging, however, there are some custom component which can be used to enable log4j.

Best regards

Sabrina