added log location

This commit is contained in:
Djeeberjr 2023-03-28 00:52:21 +02:00
parent 82827ed921
commit 409c4fb411
2 changed files with 8 additions and 6 deletions

View File

@ -25,28 +25,29 @@ class Log {
} }
public static function info(msg:Dynamic, ?pos:haxe.PosInfos) { public static function info(msg:Dynamic, ?pos:haxe.PosInfos) {
instance.log({level: Info, message: Std.string(msg),time: 0}); instance.log({level: Info, message: Std.string(msg),time: 0},pos);
} }
public static function warn(msg:Dynamic, ?pos:haxe.PosInfos) { public static function warn(msg:Dynamic, ?pos:haxe.PosInfos) {
instance.log({level: Warn, message: Std.string(msg),time: 0}); instance.log({level: Warn, message: Std.string(msg),time: 0},pos);
} }
public static function error(msg:Dynamic, ?pos:haxe.PosInfos) { public static function error(msg:Dynamic, ?pos:haxe.PosInfos) {
instance.log({level: Error, message: Std.string(msg),time: 0}); instance.log({level: Error, message: Std.string(msg),time: 0},pos);
} }
public static function debug(msg:Dynamic, ?pos:haxe.PosInfos) { public static function debug(msg:Dynamic, ?pos:haxe.PosInfos) {
#if debug #if debug
instance.log({level: Debug, message: Std.string(msg),time: 0}); instance.log({level: Debug, message: Std.string(msg),time: 0},pos);
#end #end
} }
public static function silly(msg:Dynamic, ?pos:haxe.PosInfos) { public static function silly(msg:Dynamic, ?pos:haxe.PosInfos) {
instance.log({level: Silly, message: Std.string(msg),time: 0}); instance.log({level: Silly, message: Std.string(msg),time: 0},pos);
} }
private function log(line: LogLine, ?pos:haxe.PosInfos) { private function log(line: LogLine, ?pos:haxe.PosInfos) {
line.origin = pos.className;
logLines.push(line); logLines.push(line);
if (logLines.length > MAX_LINES) { if (logLines.length > MAX_LINES) {
@ -54,7 +55,7 @@ class Log {
} }
#if webconsole #if webconsole
Debug.printWeb('[${Std.string(line.level)}] ${line.message}'); Debug.printWeb('[${Std.string(line.level)}][${line.origin}] ${line.message}');
#end #end
onLogTrigger.trigger(line); onLogTrigger.trigger(line);

View File

@ -4,4 +4,5 @@ typedef LogLine = {
level: LogLevel, level: LogLevel,
message: String, message: String,
time: Int, time: Int,
?origin: String,
} }