X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Finternal%2Fcodegen%2Futils%2FLoggingOutputStream.java;fp=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Finternal%2Fcodegen%2Futils%2FLoggingOutputStream.java;h=cc87e84bdfb3b8797245fe62d3466c25d31b2d07;hb=0861b325fcbbfa8c5985f1e11cfc39154a3808d1;hp=0000000000000000000000000000000000000000;hpb=edb5c89575392565d23dbfc7083617c981048c1e;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/LoggingOutputStream.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/LoggingOutputStream.java new file mode 100644 index 000000000..cc87e84bd --- /dev/null +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/LoggingOutputStream.java @@ -0,0 +1,50 @@ +package org.simantics.scl.compiler.internal.codegen.utils; + +import java.io.ByteArrayOutputStream; +import java.io.OutputStream; + +import org.slf4j.Logger; + +public class LoggingOutputStream extends OutputStream { + + private final ByteArrayOutputStream baos = new ByteArrayOutputStream(1000); + private final Logger logger; + private final LogLevel level; + + public enum LogLevel { + TRACE, DEBUG, INFO, WARN, ERROR, + } + + public LoggingOutputStream(Logger logger, LogLevel level) { + this.logger = logger; + this.level = level; + } + + @Override + public void write(int b) { + if (b == '\n') { + String line = baos.toString(); + baos.reset(); + + switch (level) { + case TRACE: + logger.trace(line); + break; + case DEBUG: + logger.debug(line); + break; + case ERROR: + logger.error(line); + break; + case INFO: + logger.info(line); + break; + case WARN: + logger.warn(line); + break; + } + } else { + baos.write(b); + } + } +}