package com.episode6.hackit.chop.tree;

import com.episode6.hackit.chop.Chop;

import java.io.PrintStream;

/**
 * A simple Java Tree that outputs logs to StdOut or StdErr (or both)
 */
public class StdOutDebugTree implements Chop.Tree {

  private static final String LOG_FORMAT = "::%s::%s::  %s";

  public enum OutputType {
    STD_OUT_ONLY,
    STD_ERR_ONLY,
    LOGICAL_SEPARATION
  }

  private final OutputType mOutputType;

  public StdOutDebugTree() {
    this(OutputType.LOGICAL_SEPARATION);
  }

  public StdOutDebugTree(OutputType outputType) {
    mOutputType = outputType;
  }

  @Override
  public boolean supportsLevel(Chop.Level level) {
    return true;
  }

  @Override
  public void chopLog(Chop.Level level, String tag, String message) {
    String output = String.format(LOG_FORMAT, level, tag, message);
    PrintStream printStream;
    switch (mOutputType) {
      case STD_ERR_ONLY:
        printStream = System.err;
        break;
      case STD_OUT_ONLY:
        printStream = System.out;
        break;
      default:
        printStream = level == Chop.Level.E ? System.err : System.out;
        break;
    }

    printStream.println(output);
  }
}

@@ -825,16 +825,19 @@
 e);%0A    
+get
 PrintStr
@@ -843,21 +843,110 @@
 ream
- printStream;
+ForLevel(level).println(output);%0A  %7D%0A%0A  private PrintStream getPrintStreamForLevel(Chop.Level level) %7B
 %0A   
@@ -998,37 +998,30 @@
 LY:%0A        
-printStream =
+return
  System.err;
@@ -1021,31 +1021,16 @@
 em.err;%0A
-        break;%0A
       ca
@@ -1054,29 +1054,22 @@
         
-printStream =
+return
  System.
@@ -1069,39 +1069,24 @@
 System.out;%0A
-        break;%0A
       defaul
@@ -1100,21 +1100,14 @@
     
-printStream =
+return
  lev
@@ -1160,58 +1160,9 @@
     
-    break;%0A    %7D%0A%0A    printStream.println(output);
+%7D
 %0A  %7D

clean up StdOutDebugTree