package me.hammerle.snuviscript; import java.util.Date; import me.hammerle.code.ISnuviLogger; import me.hammerle.code.Script; public class FormattedSnuviLogger implements ISnuviLogger { private final Date date = new Date(); public FormattedSnuviLogger() { } @Override public void printException(Exception thrown, String function, Script script, int line) { System.err.println(createMessage("ERROR", codeLocation(script.getName(), function, line), thrown)); } @Override public void printException(Exception thrown, String function, String scriptName, int line) { System.err.println(createMessage("ERROR", codeLocation(scriptName, function, line), thrown)); } private static String codeLocation(String scriptName, String function, int line) { return scriptName + ":" + function + ":" + line; } @Override public void printWarning(String message) { System.err.println(createMessage("WARNING", message)); } @Override public void printInfo(String message) { System.out.println(createMessage("INFO", message)); } private String createMessage(String level, String message, Exception thrown) { return String.format("%1$s%n\t%2$s", createMessage(level, message), thrown); } private String createMessage(String level, String message) { date.setTime(System.currentTimeMillis()); return String.format("[%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS] [SnuviScript|%2$s]: %3$s", date, level, message); } }