diff --git a/src/kernel/Init.hx b/src/kernel/Init.hx index 0f1ce62..80e0a50 100644 --- a/src/kernel/Init.hx +++ b/src/kernel/Init.hx @@ -16,8 +16,6 @@ class Init { Peripheral.instance = new Peripheral(); WindowManager.instance = new WindowManager(); - MainTerm.instance = new MainTerm(); - Log.init(); if (Turtle.isTurtle()){ Turtle.instance = new Turtle(); diff --git a/src/kernel/Log.hx b/src/kernel/Log.hx index 8b480d0..7354c7f 100644 --- a/src/kernel/Log.hx +++ b/src/kernel/Log.hx @@ -1,11 +1,6 @@ package kernel; -import kernel.ui.WindowContext; -import kernel.ui.WindowManager; -import kernel.ui.TermWriteable; -import lib.TermIO; #if webconsole -import kernel.net.Net; import lib.Debug; #end @@ -13,68 +8,41 @@ import lib.Debug; Log messages to specified output. **/ class Log { - private static var context:WindowContext; - private static var writer:TermIO; + private static inline final MAX_LINES:Int = 100; - /** - Depends on: WindowManager - **/ - @:allow(kernel.Init) - private static function init() { - Log.context = WindowManager.instance.createNewContext(); - Log.writer = new TermIO(Log.context); - } - - private static function setMainoutout(newOutput:TermWriteable) { - writer = new TermIO(newOutput); - } + private static final logLines:Array = []; public static function info(msg:Dynamic, ?pos:haxe.PosInfos) { - writer.writeLn(logLine("INFO",pos,msg)); - #if webconsole - Debug.printWeb(logLine("INFO",pos,msg)); - #end + log({level: Info, message: Std.string(msg),time: 0}); } public static function warn(msg:Dynamic, ?pos:haxe.PosInfos) { - writer.writeLn(logLine("WARN",pos,msg), Yellow); - #if webconsole - Debug.printWeb(logLine("WARN",pos,msg)); - #end + log({level: Warn, message: Std.string(msg),time: 0}); } public static function error(msg:Dynamic, ?pos:haxe.PosInfos) { - writer.writeLn(logLine("ERRO",pos,msg), Red); - #if webconsole - Debug.printWeb(logLine("ERRO",pos,msg)); - #end + log({level: Error, message: Std.string(msg),time: 0}); } public static function debug(msg:Dynamic, ?pos:haxe.PosInfos) { #if debug - writer.writeLn(logLine("DEBG",pos,msg), Gray); - #if webconsole - Debug.printWeb(logLine("DEBG",pos,msg)); - #end + log({level: Debug, message: Std.string(msg),time: 0}); #end } public static function silly(msg:Dynamic, ?pos:haxe.PosInfos) { - writer.writeLn(logLine("SILY",pos,msg), LightGray); + log({level: Silly, message: Std.string(msg),time: 0}); + } + + private static function log(line: LogLine, ?pos:haxe.PosInfos) { + logLines.push(line); + + if (logLines.length > MAX_LINES) { + logLines.shift(); + } + #if webconsole - Debug.printWeb(logLine("SILY",pos,msg)); - #end - } - - public static function moveToOutput(addr:String) { - WindowManager.instance.focusContextToOutput(context, addr); - } - - private static function logLine(tag: String,pos: haxe.PosInfos,msg: Dynamic): String { - #if debug - return '[$tag][${pos.className}:${pos.lineNumber}]: ${Std.string(msg)}'; - #else - return '[$tag]: ${Std.string(msg)}'; + Debug.printWeb('[${Std.string(line.level)}] ${line.message}'); #end } } diff --git a/src/kernel/LogLevel.hx b/src/kernel/LogLevel.hx new file mode 100644 index 0000000..b7fd7d2 --- /dev/null +++ b/src/kernel/LogLevel.hx @@ -0,0 +1,9 @@ +package kernel; + +enum LogLevel { + Info; + Warn; + Error; + Debug; + Silly; +} diff --git a/src/kernel/LogLine.hx b/src/kernel/LogLine.hx new file mode 100644 index 0000000..348048e --- /dev/null +++ b/src/kernel/LogLine.hx @@ -0,0 +1,9 @@ +package kernel; + +import kernel.LogLevel; + +typedef LogLine = { + level: LogLevel, + message: String, + time: Int, +}