package ethanjones.cubes.core.logging.loggers;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import ethanjones.cubes.core.logging.LogLevel;
import ethanjones.cubes.core.logging.LogWriter;

public abstract class TextLogWriter implements LogWriter {

  private final static SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yy HH:mm:ss");

  @Override
  public void log(LogLevel level, String message) {
    println(getString(level, message));
  }

  @Override
  public void log(LogLevel level, String message, Throwable throwable) {
    println(getString(level, message));
    println(getString(level, throwable));
  }

  private static String getString(LogLevel level, Throwable throwable) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    throwable.printStackTrace(pw);
    return sw.toString();
  }

  @Override
  public void log(LogLevel level, Throwable throwable) {
    println(getString(level, throwable));
  }

  protected abstract void println(String string);

  private static String getString(LogLevel level, String message) {
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(dateFormat.format(new Date()));
    stringBuilder.append(" [");
    stringBuilder.append(level.name().toUpperCase());
    stringBuilder.append("] [");
    stringBuilder.append(Thread.currentThread().getName());
    stringBuilder.append("] ");
    stringBuilder.append(message);
    return stringBuilder.toString();
  }
}

@@ -329,23 +329,16 @@
 e final 
-static 
 SimpleDa
@@ -403,16 +403,16 @@
 m:ss%22);%0A
+
 %0A  @Over
@@ -689,231 +689,8 @@
  %7D%0A%0A
-  private static String getString(LogLevel level, Throwable throwable) %7B%0A    StringWriter sw = new StringWriter();%0A    PrintWriter pw = new PrintWriter(sw);%0A    throwable.printStackTrace(pw);%0A    return sw.toString();%0A  %7D%0A%0A
   @O
@@ -867,13 +867,19 @@
 te s
-tatic
+ynchronized
  Str
@@ -1284,16 +1284,16 @@
 ssage);%0A
-
     retu
@@ -1324,11 +1324,227 @@
 g();%0A  %7D
+%0A%0A  private String getString(LogLevel level, Throwable throwable) %7B%0A    StringWriter sw = new StringWriter();%0A    PrintWriter pw = new PrintWriter(sw);%0A    throwable.printStackTrace(pw);%0A    return sw.toString();%0A  %7D
 %0A%7D%0A

Call to static DateFormat