moved log to own package

This commit is contained in:
2023-01-30 02:59:55 +01:00
parent 77d330a71d
commit a9eb569a02
10 changed files with 11 additions and 7 deletions

48
src/kernel/log/Log.hx Normal file
View File

@@ -0,0 +1,48 @@
package kernel.log;
#if webconsole
import lib.Debug;
#end
/**
Log messages to specified output.
**/
class Log {
private static inline final MAX_LINES:Int = 100;
private static final logLines:Array<LogLine> = [];
public static function info(msg:Dynamic, ?pos:haxe.PosInfos) {
log({level: Info, message: Std.string(msg),time: 0});
}
public static function warn(msg:Dynamic, ?pos:haxe.PosInfos) {
log({level: Warn, message: Std.string(msg),time: 0});
}
public static function error(msg:Dynamic, ?pos:haxe.PosInfos) {
log({level: Error, message: Std.string(msg),time: 0});
}
public static function debug(msg:Dynamic, ?pos:haxe.PosInfos) {
#if debug
log({level: Debug, message: Std.string(msg),time: 0});
#end
}
public static function silly(msg:Dynamic, ?pos:haxe.PosInfos) {
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('[${Std.string(line.level)}] ${line.message}');
#end
}
}