Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Jesperrekuh
Specialist
Specialist

Log4j using ThreadContext and also Custom log levels

Hi !

In open studio 7.3 (free) I've enabled log4j and configured properties with some custom log levels.

Also use MDC/ThreadContext to add custom 'columns' in my logging to make the processing and monitoring (in Elastic/Kibana) a little easier.

 

 

When Im using tRunJob with dynamic jobs defined, it triggers the corresponding job based on its given input NAME. In this scenario the ThreadContext works fine.

In a scenario where multiple jobs (when a list of multiple jobnames is given as input) runs the ThreadContext is not working, only for the first job...

I assumed ThreadContext implies its in the same thread, log suggest [main] so that should be the case.

Within properties in pattern you access it by %X{NAME}

 

Is there a different/better way or approach to implement ThreadContext? Help is suggestions appreciated!

 

Regards!

Jesper

 

For those who like to know how/what:

Here's what I've implemented so far and works.

Properties:

<CustomLevels>

<CustomLevel name="CONFIG" intLevel="310" />

<CustomLevel name="EVENT" intLevel="320" />

<CustomLevel name="SQL" intLevel="330" />

</CustomLevels>

 

I add java-component and add the following code:

 

Java-code in java component:

// Code

org.apache.logging.log4j.ThreadContext.put("NAME", "Example"); 

log.log( org.apache.logging.log4j.Level.getLevel("EVENT") ,"SQL-scripts");

 

Log result(s):

[statistics] connected

Example 14:25:58.511 [main] EVENT SQL-scripts

Example 14:25:58.699 [main] CONFIG Parameters jobName:PerfectView, taskName:ExtractSources, initialLoad:false, startDT:2010-01-01T00:00:00.000+0100, endDT:2020-08-20T23:59:59.000+0200, jsonConfigFilePath:/data/PROD_jobconfig_tos.json

[statistics] disconnected

 

Labels (3)
0 Replies