package kernel; import kernel.ui.WindowContext; import kernel.ui.WindowManager; import kernel.ui.TermWriteable; import lib.TermIO; #if webconsole import kernel.net.Net; import util.Debug; #end /** Log messages to specified output. **/ class Log { private static var context:WindowContext; private static var writer:TermIO; /** Depends on: WindowManager **/ @:allow(kernel.Init) private static function init() { Log.context = WindowManager.instance.createNewContext(); Log.writer = new TermIO(Log.context); } private static function setMainoutout(newOutput:TermWriteable) { writer = new TermIO(newOutput); } public static function info(msg:Dynamic, ?pos:haxe.PosInfos) { writer.writeLn(logLine("INFO",pos,msg)); #if webconsole Debug.printWeb(logLine("INFO",pos,msg)); #end } public static function warn(msg:Dynamic, ?pos:haxe.PosInfos) { writer.writeLn(logLine("WARN",pos,msg), Yellow); #if webconsole Debug.printWeb(logLine("WARN",pos,msg)); #end } public static function error(msg:Dynamic, ?pos:haxe.PosInfos) { writer.writeLn(logLine("ERRO",pos,msg), Red); #if webconsole Debug.printWeb(logLine("ERRO",pos,msg)); #end } public static function debug(msg:Dynamic, ?pos:haxe.PosInfos) { #if debug writer.writeLn(logLine("DEBG",pos,msg), Gray); #if webconsole Debug.printWeb(logLine("DEBG",pos,msg)); #end #end } public static function silly(msg:Dynamic, ?pos:haxe.PosInfos) { writer.writeLn(logLine("SILY",pos,msg), LightGray); #if webconsole Debug.printWeb(logLine("SILY",pos,msg)); #end } public static function moveToOutput(addr:String) { WindowManager.instance.focusContextToOutput(context, addr); } private static function logLine(tag: String,pos: haxe.PosInfos,msg: Dynamic): String { #if debug return '[$tag][${pos.className}:${pos.lineNumber}]: ${Std.string(msg)}'; #else return '[$tag]: ${Std.string(msg)}'; #end } }