在kettle作业中JavaScript脚本有时候也扮演非常重要的角色,此时我们希望有一些日志记录。下面是job中JavaScript记录日志的方式。
job的js写日志的方法。
得到日志输出实例
1
|
org.pentaho.di.core.logging.LogWriter.getInstance();
|
按照日志的级别输出:
1
2
3
4
5
6
7
8
9
10
11
12
|
public
void
logMinimal(String subject, String message, Object... args)
{ println(LOG_LEVEL_MINIMAL, subject, message, args) ; }
public
void
logBasic(String subject, String message, Object... args)
{ println(LOG_LEVEL_BASIC, subject, message, args) ; }
public
void
logDetailed(String subject, String message, Object... args)
{ println(LOG_LEVEL_DETAILED, subject, message, args); }
public
void
logDebug(String subject, String message, Object... args)
{ println(LOG_LEVEL_DEBUG, subject, message, args); }
public
void
logRowlevel(String subject, String message, Object... args)
{ println(LOG_LEVEL_ROWLEVEL, subject, message, args); }
public
void
logError(String subject, String message, Object... args)
{ println(LOG_LEVEL_ERROR, subject, message, args); }
|
例子:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
var
mpType = parent_job.getVariable(
"IMPTYPE"
);
var
sStart = parent_job.getVariable(
"STARTTIME"
);
var
sEnd = parent_job.getVariable(
"ENDTIME"
);
var
sdf =
new
java.text.SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss"
);
var
cal =
new
java.util.Calendar();
var
start = sdf.parse(sStart);
cal.setTime(start);
var
month1 = cal.get(cal.MONTH);
var
end = sdf.parse(sEnd);
cal.setTime(end);
cal.add(Calendar.DATE, -1);
var
month2 = cal.get(cal.MONTH);
var
log = org.pentaho.di.core.logging.LogWriter.getInstance();
log.logMinimal(
"<周统计做特殊处理>"
,
"是否跨月:startTime-->"
+ sStart+
"; endTime-->"
+ sEnd +
"; startMonth-->"
+ month1 +
";endMonth-->"
+ month2,
""
);
if
((10080 == mpType) && (month1 != month2)){
var
nextMonthPrefix = parent_job.getVariable(
"NEXTMONTABPRE"
);
parent_job.setVariable(
"MONTHTABPRE"
, nextMonthPrefix);
log.logMinimal(
"<周统计做特殊处理>"
,
"!!!该周跨月!!!MONTHTABPRE-->"
+ nextMonthPrefix +
"; startMonth-->"
+ month1 +
";endMonth-->"
+ month2,
""
);
}
true
;
|
本文转自秋楓博客园博客,原文链接:http://www.cnblogs.com/rwxwsblog/p/4529957.html,如需转载请自行联系原作者