📄 logger.js
字号:
function uiUtil_Logger(loggedClass, logLevel) { this._super(); var className = uiUtil_Type.getTypeName(loggedClass); if (uiUtil_Logger.__instances[className] != null) { throw new uiUtil_CreateException("There shouldn't be more than one " + "instances of logger for the same class: " + className); } uiUtil_Logger.__instances[className] = this; this.__allLevels = new Array(); this.__loggedClass = loggedClass; this.__needDebugPanel = (logLevel != uiUtil_Logger.LEVEL_NONE); this.__currentLevel = null; this.setLevel(logLevel);}uiUtil_Object._inherits(uiUtil_Logger, uiUtil_Object);uiUtil_Logger.__defaultStream = null;uiUtil_Logger.__instances = new Object();uiUtil_Logger.LEVEL_NONE = 0;uiUtil_Logger.LEVEL_FATAL = 1;uiUtil_Logger.LEVEL_ERROR = 2;uiUtil_Logger.LEVEL_WARN = 3;uiUtil_Logger.LEVEL_INFO = 4;uiUtil_Logger.LEVEL_DEBUG = 5;uiUtil_Logger.LEVEL_ALL = 6;if ((typeof uiGlobal_defaultLevel) == "undefined") { uiUtil_Logger.__defaultLevel = uiUtil_Logger.LEVEL_NONE;}else { uiUtil_Logger.__defaultLevel = uiGlobal_defaultLevel;}uiUtil_Logger.prototype.__obtainStream = function(loggedClass) { var className = uiUtil_Type.getTypeName(loggedClass); var stream = null; this.__needDebugPanel = true; try { stream = uiHtml_DebugPanel.getInstance("Creator: " + className); this.__needDebugPanel = false; } catch (e1) { try { stream = uiHtml_Document.getInstance().getPrintStream(); } catch (e2) { stream = uiUtil_Logger.getDefaultPrintStream(); } } return stream;};uiUtil_Logger.prototype.setLevel = function(level) { this.__currentLevel = level; var max = level + 1; for (var i = 0; i < max; ++i) { this.__allLevels[i] = true; }};uiUtil_Logger.prototype.setStream = function(stream) { this.__stream = stream;};uiUtil_Logger.prototype.getStream = function() { if (this.__needDebugPanel) { try { this.__stream = this.__obtainStream(this.__loggedClass); } catch (e) { throw e; } } return this.__stream;};uiUtil_Logger.prototype.__logTo = function(stream, message, level) { var levelName; switch (level) { case uiUtil_Logger.LEVEL_FATAL : levelName = "FATAL"; break; case uiUtil_Logger.LEVEL_ERROR : levelName = "ERROR"; break; case uiUtil_Logger.LEVEL_WARN : levelName = "WARN"; break; case uiUtil_Logger.LEVEL_INFO : levelName = "INFO"; break; case uiUtil_Logger.LEVEL_DEBUG : levelName = "DEBUG"; break; } stream.println("[uitags " + levelName + "] " + uiUtil_Type.getTypeName(this.__loggedClass) + ": " + message);};uiUtil_Logger.prototype.__log = function(message, level) { this.__logTo(this.getStream(), message, level);};uiUtil_Logger.prototype.fatal = function(message) { if (this.__allLevels[uiUtil_Logger.LEVEL_FATAL]) { this.__log(message, uiUtil_Logger.LEVEL_FATAL); }};uiUtil_Logger.prototype.error = function(message) { if (this.__allLevels[uiUtil_Logger.LEVEL_ERROR]) { this.__log(message, uiUtil_Logger.LEVEL_ERROR); }};uiUtil_Logger.prototype.warn = function(message) { if (this.__allLevels[uiUtil_Logger.LEVEL_WARN]) { this.__log(message, uiUtil_Logger.LEVEL_WARN); }};uiUtil_Logger.prototype.info = function(message) { if (this.__allLevels[uiUtil_Logger.LEVEL_INFO]) { this.__log(message, uiUtil_Logger.LEVEL_INFO); }};uiUtil_Logger.prototype.debug = function(message) { if (this.__allLevels[uiUtil_Logger.LEVEL_DEBUG]) { this.__log(message, uiUtil_Logger.LEVEL_DEBUG); }};uiUtil_Logger.getInstance = function(optLoggedClass, optLevel) { var className = uiUtil_Type.getTypeName(optLoggedClass); if (uiUtil_Logger.__instances[className] == null) { var level = uiUtil_Type.isDefined(optLevel) ? optLevel : uiUtil_Logger.__defaultLevel; return new uiUtil_Logger(optLoggedClass, level); } return uiUtil_Logger.__instances[className];};uiUtil_Logger.getDefaultPrintStream = function() { if (uiUtil_Logger.__defaultStream == null) { uiUtil_Logger.__defaultStream = new uiUtil_Logger.PrintStream(); } return uiUtil_Logger.__defaultStream;};function uiUtil_Logger$PrintStream() { this._super();}uiUtil_Logger.PrintStream = uiUtil_Object.declareClass(uiUtil_Logger$PrintStream, uiUtil_Object);uiUtil_Logger.PrintStream.prototype.print = function(text) { alert(text);};uiUtil_Logger.PrintStream.prototype.println = function(text) { alert(text);};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -