ETL相关(二)

      使用ETL过程中,日志的输出

        默认会输出到控制台,这不是我们所需要的。这个时候需要添加监听器,捕获日志。

        LoggingBuffer loggingBuffer = KettleLogStore.getAppender(); // 获取日志适配器
        loggingBuffer.removeLoggingEventListener(new ConsoleLoggingEventListener());// 移除控制台监听器
        loggingBuffer.addLoggingEventListener(new CommonLoggingEventListener());// 添加自定义监听器


/**
 * ETL日志输出
 *
 */
@LoggingPlugin(id="commonLogging")
public class CommonLoggingEventListener implements LoggingPluginInterface {

    private transient Logger pentahoLogger = LoggerFactory.getLogger("ETLLogger");

    @Override
    public void eventAdded(KettleLoggingEvent event) {
        switch (event.getLevel()) {
            case ERROR:
                pentahoLogger.error(String.valueOf(event.getMessage()));
                break;
            case DEBUG:
            case ROWLEVEL:
                pentahoLogger.debug(String.valueOf(event.getMessage()));
                break;
            default:
                pentahoLogger.info(String.valueOf(event.getMessage()));
                break;
        }
    }

    @Override
    public void init() {
        KettleLogStore.getAppender().addLoggingEventListener(this);
    }

    public void dispose() {
        KettleLogStore.getAppender().removeLoggingEventListener(this);
    }
}


你可能感兴趣的:(ETL相关(二))