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;
扫描公众号,关注更多信息
---------------------------------------------------------------------------------我是分割线--------------------------------------------------------------------------to be a better me, talk is cheap show me the code
版权所有,转载请注明原文链接。
文中有不妥或者错误的地方还望指出,以免误人子弟。如果觉得本文对你有所帮助不妨【推荐】一下!如果你有更好的建议,可以给我留言讨论,共同进步!
再次感谢您耐心的读完本篇文章。
----------------------------------------------------------------------------------------------------------------------------------------------------------------------