Logs in the routines

One Star

Logs in the routines

Hi,
I want to log into a java routine. I work with the enterprise edition an my job is in java.
I have a joblet which create the file log with a specific schema (Cf log.png).
How can I write a message in my java routine like a twarn component ?

Thank you,
Carole
One Star

Re: Logs in the routines

Hi Carole
I don't know what's your routine like.
But you can add these code in tJava or your routine.
resumeUtil.addLog("USER_DEF_LOG", "NODE:tWarn_1", "", Thread
.currentThread().getId()
+ "", "WARN", "", "this is a warning", "", "");
tLogCatcher_1.addMessage("tWarn", "tWarn_1", 4,
"this is a warning", 42);
tLogCatcher_1Process(globalMap);
globalMap.put("tWarn_1_WARN_MESSAGES", "this is a warning");
globalMap.put("tWarn_1_WARN_PRIORITY", 4);
globalMap.put("tWarn_1_WARN_CODE", 42);

One more thing. The unique name of tLogCatcher can't be changed automatically(e.g. tLogCatcher_2).
But always it is tLogCatcher_1.
Regards,
Pedro
One Star

Re: Logs in the routines

Hi Pedro,
Thank you for the answer. I put it in my routine but I have declarations problem.
resumeUtil : can't be resolved
tLogCatcher_1 : can't be resolved
globalMap : can't be resolved as a variable
globalMap : can't be resolved
globalMap : can't be resolved
globalMap : can't be resolved
The routine doesn't have a lot of code. I verify the length of a field and I reset it with empty value if it's > 4000.
I want to log when I reset the field.

Regards,
Carole
One Star

Re: Logs in the routines

Hi
If you want to define a perfect method, we need to use Java reflection, which will make it so complicated.
Here is a custom routine for your requirement in a simple way.
package routines;
import routines.system.LogCatcherUtils;
import routines.system.ResumeUtil;
public class field_too_long {
/**
* helloExample: not return value, only print "hello" + message.
*
*
* {talendTypes} String
*
* {Category} User Defined
*
* {param} string("world") input: The string need to be printed.
* {param} LogCatcherUtils(tLogCatcher_1) input
* {param} Map(globalMap) input
* {param} ResumeUtil(resumeUtil) input
*
* {example} helloExemple("world") # hello world !.
*/
public static String String_too_long(String field, LogCatcherUtils tLogCatcher_1,final java.util.Map<String, Object> globalMap,ResumeUtil resumeUtil) {
String new_field = field;
String tmp = "";
tmp = field.replaceAll(" +", " ");
new_field = tmp.replaceAll("\t+", "\t");
if(new_field.length()>3){ //You can change it to 4000.
resumeUtil.addLog("USER_DEF_LOG", "NODE:tWarn_1", "", Thread
.currentThread().getId()
+ "", "WARN", "", "this is a warning", "", "");
tLogCatcher_1.addMessage("tWarn", "tWarn_1", 4,
"this is a warning", 42);
}
return new_field;
}
}

Regards,
Pedro
One Star

Re: Logs in the routines

Hi,
I still have errors of compilation. It's certainly due to the using of joblet.
In my tmap, i had put :
too_long.field_too_long(row1.Column1,tLogCatcher_1,globalMap,resumeUtil);
tLogCatcher_1Process(globalMap)
Is it good ? Have I to don't use joblet for the log ?

Regards,
Carole
Four Stars

Re: Logs in the routines

Hi, 
I get the same trouble here. When not using tLogCatcher_1Process(globalMap) in the routine, it seems the log is not pushed to the tLogCatcher. But when I try to add it to the routine, I get a compilation error : 

The method tLogCatcher_1Process(Map<String,Object>) is undefined for the type MyClass
Thank you in advance for your help.
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier; color: #ff2600}

15TH OCTOBER, COUNTY HALL, LONDON

Join us at the Community Lounge.

Register Now

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download