📄 logger-debug.js
字号:
} this._btnCollapse.value = "Expand"; this.isCollapsed = true; }, /** * Expands UI of LogReader. Logging functionality is not disrupted. * * @method expand */ expand : function() { this._elConsole.style.display = "block"; if(this._elFt) { this._elFt.style.display = "block"; } this._btnCollapse.value = "Collapse"; this.isCollapsed = false; }, /** * Returns related checkbox element for given filter (i.e., category or source). * * @method getCheckbox * @param {String} Category or source name. * @return {Array} Array of all filter checkboxes. */ getCheckbox : function(filter) { return this._filterCheckboxes[filter]; }, /** * Returns array of enabled categories. * * @method getCategories * @return {String[]} Array of enabled categories. */ getCategories : function() { return this._categoryFilters; }, /** * Shows log messages associated with given category. * * @method showCategory * @param {String} Category name. */ showCategory : function(sCategory) { var filtersArray = this._categoryFilters; // Don't do anything if category is already enabled // Use Array.indexOf if available... if(filtersArray.indexOf) { if(filtersArray.indexOf(sCategory) > -1) { return; } } // ...or do it the old-fashioned way else { for(var i=0; i<filtersArray.length; i++) { if(filtersArray[i] === sCategory){ return; } } } this._categoryFilters.push(sCategory); this._filterLogs(); var elCheckbox = this.getCheckbox(sCategory); if(elCheckbox) { elCheckbox.checked = true; } }, /** * Hides log messages associated with given category. * * @method hideCategory * @param {String} Category name. */ hideCategory : function(sCategory) { var filtersArray = this._categoryFilters; for(var i=0; i<filtersArray.length; i++) { if(sCategory == filtersArray[i]) { filtersArray.splice(i, 1); break; } } this._filterLogs(); var elCheckbox = this.getCheckbox(sCategory); if(elCheckbox) { elCheckbox.checked = false; } }, /** * Returns array of enabled sources. * * @method getSources * @return {Array} Array of enabled sources. */ getSources : function() { return this._sourceFilters; }, /** * Shows log messages associated with given source. * * @method showSource * @param {String} Source name. */ showSource : function(sSource) { var filtersArray = this._sourceFilters; // Don't do anything if category is already enabled // Use Array.indexOf if available... if(filtersArray.indexOf) { if(filtersArray.indexOf(sSource) > -1) { return; } } // ...or do it the old-fashioned way else { for(var i=0; i<filtersArray.length; i++) { if(sSource == filtersArray[i]){ return; } } } filtersArray.push(sSource); this._filterLogs(); var elCheckbox = this.getCheckbox(sSource); if(elCheckbox) { elCheckbox.checked = true; } }, /** * Hides log messages associated with given source. * * @method hideSource * @param {String} Source name. */ hideSource : function(sSource) { var filtersArray = this._sourceFilters; for(var i=0; i<filtersArray.length; i++) { if(sSource == filtersArray[i]) { filtersArray.splice(i, 1); break; } } this._filterLogs(); var elCheckbox = this.getCheckbox(sSource); if(elCheckbox) { elCheckbox.checked = false; } }, /** * Does not delete any log messages, but clears all printed log messages from * the console. Log messages will be printed out again if user re-filters. The * static method YAHOO.widget.Logger.reset() should be called in order to * actually delete log messages. * * @method clearConsole */ clearConsole : function() { // Clear the buffer of any pending messages this._timeout = null; this._buffer = []; this._consoleMsgCount = 0; var elConsole = this._elConsole; elConsole.innerHTML = ''; }, /** * Updates title to given string. * * @method setTitle * @param sTitle {String} New title. */ setTitle : function(sTitle) { this._title.innerHTML = this.html2Text(sTitle); }, /** * Gets timestamp of the last log. * * @method getLastTime * @return {Date} Timestamp of the last log. */ getLastTime : function() { return this._lastTime; }, formatMsg : function (entry) { var Static = YAHOO.widget.LogReader, entryFormat = this.entryFormat || (this.verboseOutput ? Static.VERBOSE_TEMPLATE : Static.BASIC_TEMPLATE), info = { category : entry.category, // Label for color-coded display label : entry.category.substring(0,4).toUpperCase(), sourceAndDetail : entry.sourceDetail ? entry.source + " " + entry.sourceDetail : entry.source, // Escape HTML entities in the log message itself for output // to console message : this.html2Text(entry.msg || entry.message || '') }; // Add time info if (entry.time && entry.time.getTime) { info.localTime = entry.time.toLocaleTimeString ? entry.time.toLocaleTimeString() : entry.time.toString(); // Calculate the elapsed time to be from the last item that // passed through the filter, not the absolute previous item // in the stack info.elapsedTime = entry.time.getTime() - this.getLastTime(); info.totalTime = entry.time.getTime() - YAHOO.widget.Logger.getStartTime(); } var msg = Static.ENTRY_TEMPLATE.cloneNode(true); if (this.verboseOutput) { msg.className += ' yui-log-verbose'; } // Bug 2061169: Workaround for YAHOO.lang.substitute() msg.innerHTML = entryFormat.replace(/\{(\w+)\}/g, function (x, placeholder) { return (placeholder in info) ? info[placeholder] : ''; }); return msg; }, /** * Converts input chars "<", ">", and "&" to HTML entities. * * @method html2Text * @param sHtml {String} String to convert. * @private */ html2Text : function(sHtml) { if(sHtml) { sHtml += ""; return sHtml.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"); } return ""; },///////////////////////////////////////////////////////////////////////////////// Private member variables/////////////////////////////////////////////////////////////////////////////// /** * Name of LogReader instance. * * @property _sName * @type String * @private */ _sName : null, //TODO: remove /** * A class member shared by all LogReaders if a container needs to be * created during instantiation. Will be null if a container element never needs to * be created on the fly, such as when the implementer passes in their own element. * * @property _elDefaultContainer * @type HTMLElement * @private */ //YAHOO.widget.LogReader._elDefaultContainer = null; /** * Buffer of log message objects for batch output. * * @property _buffer * @type Object[] * @private */ _buffer : null, /** * Number of log messages output to console. * * @property _consoleMsgCount * @type Number * @default 0 * @private */ _consoleMsgCount : 0, /** * Date of last output log message. * * @property _lastTime * @type Date * @private */ _lastTime : null, /** * Batched output timeout ID. * * @property _timeout * @type Number * @private */ _timeout : null, /** * Hash of filters and their related checkbox elements. * * @property _filterCheckboxes * @type Object * @private */ _filterCheckboxes : null, /** * Array of filters for log message categories. * * @property _categoryFilters * @type String[] * @private */ _categoryFilters : null, /** * Array of filters for log message sources. * * @property _sourceFilters * @type String[] * @private */ _sourceFilters : null, /** * LogReader container element. * * @property _elContainer * @type HTMLElement * @private */ _elContainer : null, /** * LogReader header element. * * @property _elHd * @type HTMLElement * @private */ _elHd : null, /** * LogReader collapse element. * * @property _elCollapse * @type HTMLElement * @private */ _elCollapse : null, /** * LogReader collapse button element. * * @property _btnCollapse * @type HTMLElement * @private */ _btnCollapse : null, /** * LogReader title header element. * * @property _title * @type HTMLElement * @private */ _title : null, /** * LogReader console element. * * @property _elConsole * @type HTMLElement * @private */ _elConsole : null, /** * LogReader footer element. * * @property _elFt * @type HTMLElement * @private */ _elFt : null, /** * LogReader buttons container element. * * @property _elBtns * @type HTMLElement * @private */ _elBtns : null, /** * Container element for LogReader category filter checkboxes. * * @property _elCategoryFilters * @type HTMLElement * @private */ _elCategoryFilters : null, /** * Container element for LogReader source filter checkboxes. * * @property _elSourceFilters * @type HTMLElement * @private */ _elSourceFilters : null, /** * LogReader pause button element. * * @property _btnPause * @type HTMLElement * @private */ _btnPause : null, /** * Clear button element. * * @property _btnClear * @type HTMLElement * @private */ _btnClear : null, ///////////////////////////////////////////////////////////////////////////// // // Private methods // ///////////////////////////////////////////////////////////////////////////// /** * Initializes the primary container element. * * @method _initContainerEl * @param elContainer {HTMLElement} Container element by reference or string ID. * @private */ _initContainerEl : function(elContainer) { // Validate container elContainer = YAHOO.util.Dom.get(elContainer); // Attach to existing container... if(elContainer && elContainer.tagName && (elContainer.tagName.toLowerCase() == "div")) { this._elContainer = elContainer; YAHOO.util.Dom.addClass(this._elContainer,"yui-log"); } // ...or create container from scratch else { this._elContainer = document.body.appendChild(document.createElement("div")); //this._elContainer.id = "yui-log" + this._sName; YAHOO.util.Dom.addClass(this._elContainer,"yui-log"); YAHOO.util.Dom.addClass(this._elContainer,"yui-log-container"); //YAHOO.widget.LogReader._elDefaultContainer = this._elContainer; // If implementer has provided container values, trust and set those var containerStyle = this._elContainer.style; if(this.width) { containerStyle.width = this.width; } if(this.right) { containerStyle.right = this.right; } if(this.top) { containerStyle.top = this.top; } if(this.left) { containerStyle.left = this.left; containerStyle.right = "auto"; } if(this.bottom) { containerStyle.bottom = this.bottom; containerStyle.top = "auto"; } if(this.fontSize) { containerStyle.fontSize = this.fontSize; } // For Opera if(navigator.userAgent.toLowerCase().indexOf("opera") != -1) { document.body.style += ''; } } }, /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -