made Log static class

This commit is contained in:
Djeeberjr 2023-07-27 20:35:36 +02:00
parent e1e0180502
commit a93ee1cddf
3 changed files with 15 additions and 16 deletions

View File

@ -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);

View File

@ -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();

View File

@ -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<LogLine>;
public static var onLog(default, null):Signal<LogLine>;
private final onLogTrigger:SignalTrigger<LogLine> = new SignalTrigger();
private final logLines:Array<LogLine> = [];
private static final onLogTrigger:SignalTrigger<LogLine> = new SignalTrigger();
private static final logLines:Array<LogLine> = [];
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<LogLine> {
public static function getLines():ReadOnlyArray<LogLine> {
return logLines;
}
}