Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
orawajar
Contributor III
Contributor III

Any clue using log4j2 in talend?

Hi Master,
Is there any clue how to use log4j2 in Talend?
Thank you and best regards,
Labels (2)
6 Replies
Anonymous
Not applicable

Hi,
Are you looking for log4j components which are custom components developed by our community user and shared on Talend Exchange?

Best regards
Sabrina
orawajar
Contributor III
Contributor III
Author

Hi xdshi,
Yes if any,
i know component tLog4j but it use log4j not log4j2. Can i use it with log4j2? if yes, How?
Thanks before,
Anonymous
Not applicable

Hi,
We didn't use it with log4j 2 before. Could you please give us more information about your job requirement?
Best regards
Sabrina
orawajar
Contributor III
Contributor III
Author

I need to create log file :
1. Max size of each log file is : 1Mb
2. Daily Rolling, if the date changed, it will create new log file
3. Log file name pattern : app_%d{yyyyMMdd}_%i.log (where i is sequential number if more than 1 log file created in a day).
Do you have any idea?
Thank you and best regards,
Anonymous
Not applicable

This your requirement you can achieve with log4j as well. Why are you guys using tLog4jInit and other components, the log4j support is already built in Talend itself. Look into File -> Project Settings -> Log4j. There you have the template (log4j.xml) configuration available. When you run from command line, you need to pass argument to the job to activate log4j by:
-DLOG4J_ENABLED=true

If you would like to achieve DYNAMIC FILE NAME PER JOB, then you can instead of hardcoded name use following snippet of config data:
    <appender name="STD-OUT FILE" class="org.apache.log4j.FileAppender">
       <param name="File" value="C:/p4/Logging/${TalendJob.log}.STDOUT"/>
<param name="Threshold" value="TRACE"/>
       <layout class="org.apache.log4j.PatternLayout">
           <param name="ConversionPattern" value="%d - %c -%-4r %-5p %x - %m%n" />
       </layout>
   </appender>

That's it.
regarding log4j2 I am affraid there will be required to change the class load from:
org.apache.log4j.Logger

to:
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class MyTalendClass {
   private static final Logger logger = LogManager.getLogger("MyTalendClass");

I created 2 new feature tickets available at:
Support for Apache Log4j2
This is about how I see the future logging in Talend, you can use log4j JDBC subsystem to log for database filtered messages (ERROR and WARNING and even more filtering on content.
Another story is auditing execution Talend job out of the box. The idea is that the Job template itself with log 3 basic events which are happening inside:

ENTRY - the job is going to be executed
EXIT - the job finished without issue
ERROR - the job finished with error
You can then easily see ENTRY-EXIT pairs and you know it is fine, or you log ENTRY-ERROR and something is wrong, any other combination is considered as bug.
This can be extended with also component based flow events:

tComponentEntry
tComponentError
tComponentExit
enriched by some metadata.
For such purposes there can be created specific log level for example called AUDIT which can show the sequence execution and store this sequence into database for automated checking of the health status and monitoring purposes. In case of log4j via JDBC subsystem again.
This is can be achieved by 2 ways:
There will be added somewhere to tLogCatcher and other logging components some checkboxes to capture new events. Or it will be implemented inside the Job template itself and can be configured globally via File-> Project Settings.....
I created another ticket for this, let's see if this idea will find others to support 🙂
Audit logging of job execution
Ladislav
Anonymous
Not applicable

Hello,

 

Any chance to add current date to the log name?

something like this:

<param name="file" value="${TalendJob.log}_"getCurrentDatetime()".log">

 

TIA