diff --git a/src/bin/KernelLog.hx b/src/bin/KernelLog.hx index 37b45d8..eb7414b 100644 --- a/src/bin/KernelLog.hx +++ b/src/bin/KernelLog.hx @@ -24,7 +24,7 @@ class KernelLog implements Process { statelessCtx.setRenderFunc(this.render); - Log.instance.onLog.handle(()->{ + Log.onLog.handle(()->{ statelessCtx.requestRender(); }); } @@ -33,7 +33,7 @@ class KernelLog implements Process { ctx.clear(); ctx.setCursorPos(0,0); - var lines = Log.instance.getLines(); + var lines = Log.getLines(); var height = ctx.getSize().y; var start = MathI.max(lines.length - height,0); diff --git a/src/kernel/Init.hx b/src/kernel/Init.hx index 8afc324..5ffaa4e 100644 --- a/src/kernel/Init.hx +++ b/src/kernel/Init.hx @@ -24,7 +24,7 @@ class Init { public static function initKernel() { // Init singeltons here because haxe is confused about the order to create them. - Log.instance = new Log(); + Log.init(); KernelEvents.init(); Peripheral.instance = new Peripheral(); diff --git a/src/kernel/log/Log.hx b/src/kernel/log/Log.hx index b6501c4..b191b1b 100644 --- a/src/kernel/log/Log.hx +++ b/src/kernel/log/Log.hx @@ -11,42 +11,41 @@ using tink.CoreApi; Central logging system. **/ class Log { - public static var instance:Log; - private static inline final MAX_LINES:Int = 100; - public final onLog:Signal; + public static var onLog(default, null):Signal; - private final onLogTrigger:SignalTrigger = new SignalTrigger(); - private final logLines:Array = []; + private static final onLogTrigger:SignalTrigger = new SignalTrigger(); + private static final logLines:Array = []; - public function new() { + @:allow(kernel.Init) + private static function init() { onLog = onLogTrigger.asSignal(); } public static function info(msg:Dynamic, ?pos:haxe.PosInfos) { - instance.log({level: Info, message: Std.string(msg),time: 0},pos); + log({level: Info, message: Std.string(msg),time: 0},pos); } public static function warn(msg:Dynamic, ?pos:haxe.PosInfos) { - instance.log({level: Warn, message: Std.string(msg),time: 0},pos); + log({level: Warn, message: Std.string(msg),time: 0},pos); } public static function error(msg:Dynamic, ?pos:haxe.PosInfos) { - instance.log({level: Error, message: Std.string(msg),time: 0},pos); + log({level: Error, message: Std.string(msg),time: 0},pos); } public static function debug(msg:Dynamic, ?pos:haxe.PosInfos) { #if debug - instance.log({level: Debug, message: Std.string(msg),time: 0},pos); + log({level: Debug, message: Std.string(msg),time: 0},pos); #end } public static function silly(msg:Dynamic, ?pos:haxe.PosInfos) { - instance.log({level: Silly, message: Std.string(msg),time: 0},pos); + log({level: Silly, message: Std.string(msg),time: 0},pos); } - private function log(line: LogLine, ?pos:haxe.PosInfos) { + private static function log(line: LogLine, ?pos:haxe.PosInfos) { line.origin = pos.className; logLines.push(line); @@ -60,7 +59,7 @@ class Log { #end } - public function getLines():ReadOnlyArray { + public static function getLines():ReadOnlyArray { return logLines; } }