package org.zeropage.log;

import java.io.IOException;
import java.io.OutputStream;

public class OutputStreamLogListener implements LogListener {
    private OutputStream outputStream;

    public OutputStreamLogListener(OutputStream outputStream) {
        this.outputStream = outputStream;
    }

    @Override
    public void debug(String message) {
        print("DEBUG: " + message);
    }

    @Override
    public void info(String message) {
        print("INFO: " + message);
    }

    @Override
    public void warn(String message) {
        print("WARNING: " + message);
    }

    @Override
    public void error(String message) {
        print("ERROR: " + message);
    }

    @Override
    public void fatal(String message) {
        print("FATAL: " + message);
    }

    private void print(String message) {
        message = message + System.lineSeparator();
        try {
            outputStream.write(message.getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

@@ -178,16 +178,41 @@
 tStream;
+%0A    private Level level;
 %0A%0A    pu
@@ -326,58 +326,194 @@
     
-@Override%0A    public void debug(String message) %7B%0A
+public void setLevel(Level level) %7B%0A        this.level = level;%0A    %7D%0A%0A    @Override%0A    public void debug(String message) %7B%0A        if(Level.DEBUG.getValue() %3C= level.getValue()) %7B%0A    
     
@@ -536,32 +536,43 @@
 : %22 + message);%0A
+        %7D%0A%0A
     %7D%0A%0A    @Over
@@ -607,32 +607,92 @@
 ring message) %7B%0A
+        if(Level.INFO.getValue() %3C= level.getValue()) %7B%0A    
         print(%22I
@@ -702,32 +702,42 @@
 : %22 + message);%0A
+        %7D%0A
     %7D%0A%0A    @Over
@@ -772,32 +772,92 @@
 ring message) %7B%0A
+        if(Level.WARN.getValue() %3C= level.getValue()) %7B%0A    
         print(%22W
@@ -870,32 +870,42 @@
 : %22 + message);%0A
+        %7D%0A
     %7D%0A%0A    @Over
@@ -941,32 +941,93 @@
 ring message) %7B%0A
+        if(Level.ERROR.getValue() %3C= level.getValue()) %7B%0A    
         print(%22E
@@ -1038,32 +1038,42 @@
 : %22 + message);%0A
+        %7D%0A
     %7D%0A%0A    @Over
@@ -1109,32 +1109,93 @@
 ring message) %7B%0A
+        if(Level.FATAL.getValue() %3C= level.getValue()) %7B%0A    
         print(%22F
@@ -1210,24 +1210,34 @@
 + message);%0A
+        %7D%0A
     %7D%0A%0A    p

add logging level