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}