📄 logger.js
字号:
/*Copyright (c) 2008, Yahoo! Inc. All rights reserved.Code licensed under the BSD License:http://developer.yahoo.net/yui/license.txtversion: 2.6.0*//****************************************************************************//****************************************************************************//****************************************************************************//** * The LogMsg class defines a single log message. * * @class LogMsg * @constructor * @param oConfigs {Object} Object literal of configuration params. */YAHOO.widget.LogMsg = function(oConfigs) { // Parse configs /** * Log message. * * @property msg * @type String */ this.msg = /** * Log timestamp. * * @property time * @type Date */ this.time = /** * Log category. * * @property category * @type String */ this.category = /** * Log source. The first word passed in as the source argument. * * @property source * @type String */ this.source = /** * Log source detail. The remainder of the string passed in as the source argument, not * including the first word (if any). * * @property sourceDetail * @type String */ this.sourceDetail = null; if (oConfigs && (oConfigs.constructor == Object)) { for(var param in oConfigs) { if (oConfigs.hasOwnProperty(param)) { this[param] = oConfigs[param]; } } }};/****************************************************************************//****************************************************************************//****************************************************************************//** * The LogWriter class provides a mechanism to log messages through * YAHOO.widget.Logger from a named source. * * @class LogWriter * @constructor * @param sSource {String} Source of LogWriter instance. */YAHOO.widget.LogWriter = function(sSource) { if(!sSource) { YAHOO.log("Could not instantiate LogWriter due to invalid source.", "error", "LogWriter"); return; } this._source = sSource; };///////////////////////////////////////////////////////////////////////////////// Public methods/////////////////////////////////////////////////////////////////////////////// /** * Public accessor to the unique name of the LogWriter instance. * * @method toString * @return {String} Unique name of the LogWriter instance. */YAHOO.widget.LogWriter.prototype.toString = function() { return "LogWriter " + this._sSource;};/** * Logs a message attached to the source of the LogWriter. * * @method log * @param sMsg {String} The log message. * @param sCategory {String} Category name. */YAHOO.widget.LogWriter.prototype.log = function(sMsg, sCategory) { YAHOO.widget.Logger.log(sMsg, sCategory, this._source);};/** * Public accessor to get the source name. * * @method getSource * @return {String} The LogWriter source. */YAHOO.widget.LogWriter.prototype.getSource = function() { return this._source;};/** * Public accessor to set the source name. * * @method setSource * @param sSource {String} Source of LogWriter instance. */YAHOO.widget.LogWriter.prototype.setSource = function(sSource) { if(!sSource) { YAHOO.log("Could not set source due to invalid source.", "error", this.toString()); return; } else { this._source = sSource; }};///////////////////////////////////////////////////////////////////////////////// Private member variables////////////////////////////////////////////////////////////////////////////////** * Source of the LogWriter instance. * * @property _source * @type String * @private */YAHOO.widget.LogWriter.prototype._source = null;/****************************************************************************//****************************************************************************//****************************************************************************//** * The LogReader class provides UI to read messages logged to YAHOO.widget.Logger. * * @class LogReader * @constructor * @param elContainer {HTMLElement} (optional) DOM element reference of an existing DIV. * @param elContainer {String} (optional) String ID of an existing DIV. * @param oConfigs {Object} (optional) Object literal of configuration params. */YAHOO.widget.LogReader = function(elContainer, oConfigs) { this._sName = YAHOO.widget.LogReader._index; YAHOO.widget.LogReader._index++; // Internal vars this._buffer = []; // output buffer this._filterCheckboxes = {}; // pointers to checkboxes this._lastTime = YAHOO.widget.Logger.getStartTime(); // timestamp of last log message to console // Parse config vars here if (oConfigs && (oConfigs.constructor == Object)) { for(var param in oConfigs) { if (oConfigs.hasOwnProperty(param)) { this[param] = oConfigs[param]; } } } this._initContainerEl(elContainer); if(!this._elContainer) { YAHOO.log("Could not instantiate LogReader due to an invalid container element " + elContainer, "error", this.toString()); return; } this._initHeaderEl(); this._initConsoleEl(); this._initFooterEl(); this._initDragDrop(); this._initCategories(); this._initSources(); // Subscribe to Logger custom events YAHOO.widget.Logger.newLogEvent.subscribe(this._onNewLog, this); YAHOO.widget.Logger.logResetEvent.subscribe(this._onReset, this); YAHOO.widget.Logger.categoryCreateEvent.subscribe(this._onCategoryCreate, this); YAHOO.widget.Logger.sourceCreateEvent.subscribe(this._onSourceCreate, this); this._filterLogs(); YAHOO.log("LogReader initialized", null, this.toString());};///////////////////////////////////////////////////////////////////////////////// Static member variables///////////////////////////////////////////////////////////////////////////////YAHOO.lang.augmentObject(YAHOO.widget.LogReader, { /** * Internal class member to index multiple LogReader instances. * * @property _memberName * @static * @type Number * @default 0 * @private */ _index : 0, /** * Node template for the log entries * @property ENTRY_TEMPLATE * @static * @type {HTMLElement} * @default PRE.yui-log-entry element */ ENTRY_TEMPLATE : (function () { var t = document.createElement('pre'); YAHOO.util.Dom.addClass(t,'yui-log-entry'); return t; })(), /** * Template used for innerHTML of verbose entry output. * @property VERBOSE_TEMPLATE * @static * @default "<span class='{category}'>{label}</span>{totalTime}ms (+{elapsedTime}) {localTime}:</p><p>{sourceAndDetail}</p><p>{message}</p>" */ VERBOSE_TEMPLATE : "<p><span class='{category}'>{label}</span> {totalTime}ms (+{elapsedTime}) {localTime}:</p><p>{sourceAndDetail}</p><p>{message}</p>", /** * Template used for innerHTML of compact entry output. * @property BASIC_TEMPLATE * @static * @default "<p><span class='{category}'>{label}</span>{totalTime}ms (+{elapsedTime}) {localTime}: {sourceAndDetail}: {message}</p>" */ BASIC_TEMPLATE : "<p><span class='{category}'>{label}</span> {totalTime}ms (+{elapsedTime}) {localTime}: {sourceAndDetail}: {message}</p>"});///////////////////////////////////////////////////////////////////////////////// Public member variables///////////////////////////////////////////////////////////////////////////////YAHOO.widget.LogReader.prototype = { /** * Whether or not LogReader is enabled to output log messages. * * @property logReaderEnabled * @type Boolean * @default true */ logReaderEnabled : true, /** * Public member to access CSS width of the LogReader container. * * @property width * @type String */ width : null, /** * Public member to access CSS height of the LogReader container. * * @property height * @type String */ height : null, /** * Public member to access CSS top position of the LogReader container. * * @property top * @type String */ top : null, /** * Public member to access CSS left position of the LogReader container. * * @property left * @type String */ left : null, /** * Public member to access CSS right position of the LogReader container. * * @property right * @type String */ right : null, /** * Public member to access CSS bottom position of the LogReader container. * * @property bottom * @type String */ bottom : null, /** * Public member to access CSS font size of the LogReader container. * * @property fontSize * @type String */ fontSize : null, /** * Whether or not the footer UI is enabled for the LogReader. * * @property footerEnabled * @type Boolean * @default true */ footerEnabled : true, /** * Whether or not output is verbose (more readable). Setting to true will make * output more compact (less readable). * * @property verboseOutput * @type Boolean * @default true */ verboseOutput : true, /** * Custom output format for log messages. Defaults to null, which falls * back to verboseOutput param deciding between LogReader.VERBOSE_TEMPLATE * and LogReader.BASIC_TEMPLATE. Use bracketed place holders to mark where * message info should go. Available place holder names include: * <ul> * <li>category</li> * <li>label</li> * <li>sourceAndDetail</li> * <li>message</li> * <li>localTime</li> * <li>elapsedTime</li> * <li>totalTime</li> * </ul> * * @property entryFormat * @type String * @default null */ entryFormat : null, /** * Whether or not newest message is printed on top. * * @property newestOnTop * @type Boolean */ newestOnTop : true, /** * Output timeout buffer in milliseconds. * * @property outputBuffer * @type Number * @default 100 */ outputBuffer : 100, /** * Maximum number of messages a LogReader console will display. * * @property thresholdMax * @type Number * @default 500 */ thresholdMax : 500, /** * When a LogReader console reaches its thresholdMax, it will clear out messages * and print out the latest thresholdMin number of messages. * * @property thresholdMin * @type Number * @default 100 */ thresholdMin : 100, /** * True when LogReader is in a collapsed state, false otherwise. * * @property isCollapsed * @type Boolean * @default false */ isCollapsed : false, /** * True when LogReader is in a paused state, false otherwise. * * @property isPaused * @type Boolean * @default false */ isPaused : false, /** * Enables draggable LogReader if DragDrop Utility is present. * * @property draggable * @type Boolean * @default true */ draggable : true, ///////////////////////////////////////////////////////////////////////////// // // Public methods // ///////////////////////////////////////////////////////////////////////////// /** * Public accessor to the unique name of the LogReader instance. * * @method toString * @return {String} Unique name of the LogReader instance. */ toString : function() { return "LogReader instance" + this._sName; }, /** * Pauses output of log messages. While paused, log messages are not lost, but * get saved to a buffer and then output upon resume of LogReader. * * @method pause */ pause : function() { this.isPaused = true; this._timeout = null; this.logReaderEnabled = false; if (this._btnPause) { this._btnPause.value = "Resume"; } }, /** * Resumes output of log messages, including outputting any log messages that * have been saved to buffer while paused. * * @method resume */ resume : function() { this.isPaused = false; this.logReaderEnabled = true; this._printBuffer(); if (this._btnPause) { this._btnPause.value = "Pause"; } }, /** * Hides UI of LogReader. Logging functionality is not disrupted. * * @method hide */ hide : function() { this._elContainer.style.display = "none"; }, /** * Shows UI of LogReader. Logging functionality is not disrupted. * * @method show */ show : function() { this._elContainer.style.display = "block"; }, /** * Collapses UI of LogReader. Logging functionality is not disrupted. * * @method collapse */ collapse : function() { this._elConsole.style.display = "none"; if(this._elFt) { this._elFt.style.display = "none";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -