⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 log.js

📁 javascript 很酷的类库
💻 JS
📖 第 1 页 / 共 5 页
字号:
	// index of the slot for the next message in messageCache	_messageIndex:0,					// array for keeping log messages	_messageCache:[],    _semiColon : ":",    _dot : ".",    _allCategories : "_allCategories",    _default : "_default"});isc.Log.addClassMethods({    // Log Priorities	// --------------------------------------------------------------------------------------------    //> @classMethod Log.applyLogPriorities()    // Apply a batch a batch of priority settings, as a object mapping category names to priority    // levels.    //    // @param settings (Object) priority settings for multiple categories    // @visibility external    //<	applyLogPriorities : function (newDefaults) {		// make a blank priority defaults object if necessary		if (!this._logPriorities) {            this._logPriorities = {};        }            		// if new defaults were specified, overlay them on the current set		if (newDefaults) {			isc.addProperties(this._logPriorities, newDefaults);		}	},	    //> @classMethod Log.getLogPriorities()    // Get all priority settings as an object mapping category names to priority levels.    //    // @param [object] (Class or Instance object) Optional param to get priorities specific to    //                                            some ISC class or instance.    // @param [overridesOnly] (boolean) If this method is retrieving the priorities specific     //                                  to logging for some class or instance, this parameter    //                                  can be used to view only the overrides to the default    //                                  log priorites on this object.    // @return (Object) priority settings    // @visibility external    //<	getLogPriorities : function (object, overridesOnly) {        var overrides;        if (object != null) {            var objectID = this._getObjectID(object);                        overrides = this._objectLogPriorities[objectID];            if (overridesOnly) {                return isc.addProperties({}, overrides);            }        }                // copy to avoid unintentional changes        var priorities = isc.addProperties({}, this._logPriorities);        if (overrides) priorities = isc.addProperties(priorities, overrides);                return priorities;	},            _getObjectID : function (object) {        var ID;        if (object == null) ID = isc.emptyString;        else ID = (object.getID ? object.getID() : object.getClassName());        return ID;    },	    //> @classMethod Log.getPriority()	// Return the priority setting for a particular category.    // <P>    // If there is no priority setting specific to this category, <code>null</code> will be    // returned, NOT <code>Log.defaultPriority</code>.    //    // @param   category   (String)            category name    // @param [object] (Class or Instance object)   Optional class or instance to check for     //                                              specific log priority overrides    // @return  (LogPriority)     priority setting    // @visibility external    //<	// return the priority for a particular category	getPriority : function (category, object) {                if (object != null) {            var objectID = this._getObjectID(object),                overrides = this._objectLogPriorities[objectID];            if (overrides) {                if (overrides._allCategories != null) return overrides._allCategories;                if (overrides[category] != null) return overrides[category];                if (overrides._default != null) return overrides._default;            }        }                // Still going - look at global settings        var priorities = this._logPriorities;        return priorities[category] || priorities._default;	},    //> @classMethod Log.setPriority()    // Set the priority of messages that will be visible for this log category.    // <P>    // After calling setPriority, any messages logged to the given category whose priority is    // below the specified priority will not appear in the Log.    //    // @param category   (String)            category name    // @param priority   (LogPriority)  priority level to set    // @param [object]   (Class or Instance object)     //      Optional ISC class or instance - if passed the priority will be set for logging     //      occurring on the class or instance only.    // @see Log.isEnabledFor() to check whether a category would allow a log at a given priority    // @visibility external    //<	setPriority : function (category, priority, object) {        if (object != null) {            var objectID = this._getObjectID(object);            if (this._objectLogPriorities[objectID] == null)                 this._objectLogPriorities[objectID] = {};            // If we're not passed a category, ensure we show all logs on the object in question            // at the appropriate priority.            if (!category) category = this._allCategories;            this._objectLogPriorities[objectID][category] = priority;        } else {                    this._logPriorities[category] = priority;        }	},        //> @classMethod Log.setDefaultPriority()    // Set the default priority of messages that will be visible.    //    // @param priority   (LogPriority)  priority level to set    // @param [object]   (Class or Instance object)     //      Optional ISC class or instance - if passed the default priority will be set for logging     //      occurring on the class or instance only.    // @visibility external    //<    setDefaultPriority : function (priority, object) {        if (!object || object == isc.Log) isc.Log.defaultPriority = priority;        else isc.Log.setPriority("_default", priority, object);     },        //> @classMethod Log.getDefaultPriority()    // Retrieves the default priority of messages that will be visible.    //    // @param [object]   (Class or Instance object)     //      Optional ISC class or instance - if passed the returns the default priority for     //     the class or instance only.    // @return (LogPriority) default priority for which messages will be logged.    // @visibility external    //<    getDefaultPriority : function (object) {        var defaultPriority;        if (object && object != isc.Log) defaultPriority = this.getPriority("_default", object);        return defaultPriority || isc.Log.defaultPriority;    },    //> @classMethod Log.clearPriority()	// Clear the priority setting for a particular category, so that the category's effective    // priority returns to <code>Log.defaultPriority</code><br>    // If the optional second parameter is passed, the specific priority setting for the     // category on that object will be cleared, so logs in that category on that object will    // be logged at the global priority level for the category.    //    // @param category   (String)            category name    // @param [object] (Class or Instance object) Optional instance or class object - if passed    //                                        clear logging priority for the appropriate category    //                                        on that object.    // @visibility external    //<	clearPriority : function (category, object) {        if (object) {            var objectID = this._getObjectID(object);                        // If we were passed no category, clear all explicit log priorities on the object            // in question.            if (!category)                 delete this._objectLogPriorities[objectID];            else if (this._objectLogPriorities[objectID])                 delete this._objectLogPriorities[objectID][category];                    } else {            delete this._logPriorities[category];        }	},    //> @classMethod Log.isEnabledFor()	// Would a message logged to the given category at the given priority appear in the Log?    // <P>    // NOTE: if there is no specific priority setting for a given category, the    // <code>Log.defaultPriority</code> is used.    //    // @param category   (String)            category name    // @param priority   (LogPriority)  priority level to check    //    // @visibility external    //<    // NOTE: hierarchical categories are not documented; not clear whether we want to expose this    // feature	isEnabledFor : function (category, priority, object) {        if (!category) category = isc._emptyString;		while (category != isc._emptyString) {        			// get the priority for the category			var categoryPriority = this.getPriority(category, object);			// if it was found and its priority is set			if (categoryPriority != null) {				// return if the message is at the appropriate priority				return priority <= categoryPriority;			}						// if the category contains a period, chop it down and try again			var periodIndex = category.lastIndexOf(this._dot);			if (periodIndex > 0) {				// chop off the last category				category = category.substring(0, periodIndex);			} else {				// jump out of the loop				break;			}			}		// category not found or was null -- return according to the default logging priority		return priority <= isc.Log.defaultPriority;	},    // Formatting and Displaying Log messages	// --------------------------------------------------------------------------------------------	// log a message at an arbitrary priority (for wrappers)	log : function (priority, message, category, msgPrefix, object, timestamp) {		if (this.isEnabledFor(category, priority, object))			this.addLogMessage(priority, message, category, msgPrefix, timestamp);        else if (this.reportSuppressedLogs) {            // Useful for detecting unnecessary logs, especially unnecessary logs during            // critical path code            this.logWarn("suppressed log, category: " + category + ": " + message                // + this.getStackTrace()            );        }	},    // get a timestamp suitable for our short-lived log: millisecond precision, no need to show    // date         _1zero : "0",    _2zero : "00",	getLogTimestamp : function (date) {        var tsArray = this._tsArray;        if (tsArray == null) {            tsArray = this._tsArray = [];             tsArray[2] = this._semiColon;            tsArray[5] = this._semiColon;            tsArray[8] = this._dot;        }		if (date == null) date = new Date();        var hours = date.getHours(),            minutes = date.getMinutes(),            seconds = date.getSeconds(),            ms = date.getMilliseconds();                 tsArray[1] = hours;        if (hours < 10) tsArray[0] = this._1zero;        else tsArray[0] = null;        tsArray[4] = minutes;        if (minutes < 10) tsArray[3] = this._1zero;        else tsArray[3] = null;        tsArray[7] = seconds;        if (seconds < 10) tsArray[6] = this._1zero;        else tsArray[6] = null;        tsArray[10] = ms;        if (ms < 10) tsArray[9] = this._2zero;        else if (ms < 100) tsArray[9] = this._1zero;        else tsArray[9] = null;                return tsArray.join(isc._emptyString);	},	// return the name shown to the user for a particular log priority	getPriorityName : function (priority) {		if (priority == null) return isc._emptyString;		return this.PRIORITY_NAMES[priority];	},	// routine to format the log message and officially "log" it	// override to set your own outputter	_makeLogMessage : function (priority, message, category, msgPrefix, timestamp) {        var msg = this._msgArray;        if (msg == null) {            msg = this._msgArray = [];        }        		if (!category) category = this.category;		        msg[0] = this.getLogTimestamp(timestamp);        msg[1] = this._semiColon;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -