转载

kettle作业中的js如何写日志文件

在kettle作业中JavaScript脚本有时候也扮演非常重要的角色,此时我们希望有一些日志记录。下面是job中JavaScript记录日志的方式。

job的js写日志的方法。

得到日志输出实例

org.pentaho.di.core.logging.LogWriter.getInstance();

按照日志的级别输出:

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); }

例子:

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;
正文到此结束
Loading...