54 lines
1.6 KiB
Haxe
Executable File
54 lines
1.6 KiB
Haxe
Executable File
package haxework.log;
|
|
|
|
#if flash
|
|
import flash.events.ErrorEvent;
|
|
import flash.errors.Error;
|
|
#end
|
|
import haxework.log.ILogger.LogLevel;
|
|
|
|
class BaseLogger implements ILogger {
|
|
|
|
public function new() {}
|
|
|
|
public function log(level:LogLevel, tag:String, message:String, ?error:Dynamic, ?p:haxe.PosInfos):Void {
|
|
write(buildString(level, tag, message, error), p);
|
|
}
|
|
|
|
private function buildString(level:LogLevel, tag:String, message:String, ?error:Dynamic):String {
|
|
return "[" + level + "] " + tag + " - " + message + (error == null ? "" : " {" + error2strign(error) + "}");
|
|
}
|
|
|
|
public static function error2strign(error:Dynamic):String {
|
|
#if flash
|
|
return if (Std.is(error, Error)) {
|
|
var stack:String = error.getStackTrace();
|
|
stack == null ? Std.string(error) : stack;
|
|
} else if (Std.is(error, ErrorEvent)) {
|
|
var event:ErrorEvent = cast(error, ErrorEvent);
|
|
event.type + " - " + event.text;
|
|
} else {
|
|
Std.string(error);
|
|
}
|
|
#else
|
|
return Std.string(error);
|
|
#end
|
|
}
|
|
|
|
private function write(text:String, ?p:haxe.PosInfos):Void {}
|
|
|
|
public function d(tag:String, message:String, ?error:Dynamic, ?p:haxe.PosInfos):Void {
|
|
log(LogLevel.DEBUG, tag, message, error, p);
|
|
}
|
|
|
|
public function i(tag:String, message:String, ?error:Dynamic, ?p:haxe.PosInfos):Void {
|
|
log(LogLevel.INFO, tag, message, error, p);
|
|
}
|
|
|
|
public function w(tag:String, message:String, ?error:Dynamic, ?p:haxe.PosInfos):Void {
|
|
log(LogLevel.WARNING, tag, message, error, p);
|
|
}
|
|
|
|
public function e(tag:String, message:String, ?error:Dynamic, ?p:haxe.PosInfos):Void {
|
|
log(LogLevel.ERROR, tag, message, error, p);
|
|
}
|
|
} |