001/* 002 * (C) Copyright 2017 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bdelbosc 018 */ 019package org.nuxeo.lib.stream.tools.renderer; 020 021import java.nio.file.Paths; 022 023import org.apache.commons.logging.Log; 024import org.apache.commons.logging.LogFactory; 025import org.nuxeo.lib.stream.codec.FileAvroSchemaStore; 026import org.nuxeo.lib.stream.computation.Record; 027import org.nuxeo.lib.stream.log.LogRecord; 028 029/** 030 * @since 9.3 031 */ 032public class MarkdownRenderer extends Renderer { 033 private static final Log log = LogFactory.getLog(Renderer.class); 034 035 protected static final String MD_DATA = "```"; 036 037 protected final FileAvroSchemaStore schemaStore; 038 039 public MarkdownRenderer(String avroSchemaStorePath, int dataSize) { 040 if (avroSchemaStorePath != null) { 041 schemaStore = new FileAvroSchemaStore(Paths.get(avroSchemaStorePath)); 042 } else { 043 schemaStore = null; 044 } 045 this.dataSize = dataSize; 046 } 047 048 @Override 049 public void accept(LogRecord<Record> record) { 050 Record rec = record.message(); 051 log.info(String.format("### %s: key: %s, wm: %s, len: %d, flag: %s", record.offset(), rec.getKey(), 052 watermarkString(rec.getWatermark()), rec.getData().length, rec.getFlags())); 053 log.info(MD_DATA + tryToRenderAvroData(schemaStore, rec) + MD_DATA); 054 } 055 056 @Override 057 public void header() { 058 log.info("## Records"); 059 } 060 061 @Override 062 public void footer() { 063 log.info(""); 064 } 065}