📄 logger.js
字号:
// If implementer has provided container values, trust and set those
if(this.left) {
this._containerEl.style.left = this.left;
}
if(this.right) {
this._containerEl.style.right = this.right;
}
if(this.bottom) {
this._containerEl.style.bottom = this.bottom;
}
if(this.top) {
this._containerEl.style.top = this.top;
}
if(this.fontSize) {
this._containerEl.style.fontSize = this.fontSize;
}
}
if(this._containerEl) {
// Create header
if(!this._hdEl) {
this._hdEl = this._containerEl.appendChild(document.createElement("div"));
this._hdEl.id = "ylog_hd" + YAHOO.widget.LogReader._index;
this._hdEl.className = "ylog_hd";
this._collapseEl = this._hdEl.appendChild(document.createElement("div"));
this._collapseEl.className = "ylog_btns";
this._collapseBtn = document.createElement("input");
this._collapseBtn.type = "button";
this._collapseBtn.style.fontSize = YAHOO.util.Dom.getStyle(this._containerEl,"fontSize");
this._collapseBtn.className = "button";
this._collapseBtn.value = "Collapse";
this._collapseBtn = this._collapseEl.appendChild(this._collapseBtn);
YAHOO.util.Event.addListener(oSelf._collapseBtn,'click',oSelf._onClickCollapseBtn,oSelf);
this._title = this._hdEl.appendChild(document.createElement("h4"));
this._title.innerHTML = "Logger Console";
// If Drag and Drop utility is available...
// ...and this container was created from scratch...
// ...then make the header draggable
if(YAHOO.util.DD &&
(YAHOO.widget.LogReader._defaultContainerEl == this._containerEl)) {
var ylog_dd = new YAHOO.util.DD(this._containerEl.id);
ylog_dd.setHandleElId(this._hdEl.id);
this._hdEl.style.cursor = "move";
}
}
// Ceate console
if(!this._consoleEl) {
this._consoleEl = this._containerEl.appendChild(document.createElement("div"));
this._consoleEl.className = "ylog_bd";
// If implementer has provided console, trust and set those
if(this.height) {
this._consoleEl.style.height = this.height;
}
}
// Don't create footer if disabled
if(!this._ftEl && this.footerEnabled) {
this._ftEl = this._containerEl.appendChild(document.createElement("div"));
this._ftEl.className = "ylog_ft";
this._btnsEl = this._ftEl.appendChild(document.createElement("div"));
this._btnsEl.className = "ylog_btns";
this._pauseBtn = document.createElement("input");
this._pauseBtn.type = "button";
this._pauseBtn.style.fontSize = YAHOO.util.Dom.getStyle(this._containerEl,"fontSize");
this._pauseBtn.className = "button";
this._pauseBtn.value = "Pause";
this._pauseBtn = this._btnsEl.appendChild(this._pauseBtn);
YAHOO.util.Event.addListener(oSelf._pauseBtn,'click',oSelf._onClickPauseBtn,oSelf);
this._clearBtn = document.createElement("input");
this._clearBtn.type = "button";
this._clearBtn.style.fontSize = YAHOO.util.Dom.getStyle(this._containerEl,"fontSize");
this._clearBtn.className = "button";
this._clearBtn.value = "Clear";
this._clearBtn = this._btnsEl.appendChild(this._clearBtn);
YAHOO.util.Event.addListener(oSelf._clearBtn,'click',oSelf._onClickClearBtn,oSelf);
this._categoryFiltersEl = this._ftEl.appendChild(document.createElement("div"));
this._categoryFiltersEl.className = "ylog_categoryfilters";
this._sourceFiltersEl = this._ftEl.appendChild(document.createElement("div"));
this._sourceFiltersEl.className = "ylog_sourcefilters";
}
}
// Initialize buffer
if(!this._buffer) {
this._buffer = []; // output buffer
}
YAHOO.widget.Logger.newLogEvent.subscribe(this._onNewLog, this);
this._lastTime = YAHOO.widget.Logger.getStartTime(); // timestamp of last log message to console
// Initialize category filters
this._categoryFilters = [];
var catsLen = YAHOO.widget.Logger.categories.length;
if(this._categoryFiltersEl) {
for(var i=0; i < catsLen; i++) {
this._createCategoryCheckbox(YAHOO.widget.Logger.categories[i]);
}
}
// Initialize source filters
this._sourceFilters = [];
var sourcesLen = YAHOO.widget.Logger.sources.length;
if(this._sourceFiltersEl) {
for(var j=0; j < sourcesLen; j++) {
this._createSourceCheckbox(YAHOO.widget.Logger.sources[j]);
}
}
YAHOO.widget.Logger.categoryCreateEvent.subscribe(this._onCategoryCreate, this);
YAHOO.widget.Logger.sourceCreateEvent.subscribe(this._onSourceCreate, this);
YAHOO.widget.LogReader._index++;
this._filterLogs();
};
/***************************************************************************
* Public members
***************************************************************************/
/**
* Whether or not the log reader is enabled to output log messages.
*
* @type boolean
*/
YAHOO.widget.LogReader.prototype.logReaderEnabled = true;
/**
* CSS width of the log reader container.
*
* @type string
*/
YAHOO.widget.LogReader.prototype.width = null;
/**
* CSS height of the log reader container.
*
* @type string
*/
YAHOO.widget.LogReader.prototype.height = null;
/**
* CSS top position of the log reader container.
*
* @type string
*/
YAHOO.widget.LogReader.prototype.top = null;
/**
* CSS left position of the log reader container.
*
* @type string
*/
YAHOO.widget.LogReader.prototype.left = null;
/**
* CSS right position of the log reader container.
*
* @type string
*/
YAHOO.widget.LogReader.prototype.right = null;
/**
* CSS bottom position of the log reader container.
*
* @type string
*/
YAHOO.widget.LogReader.prototype.bottom = null;
/**
* CSS font size of the log reader container.
*
* @type string
*/
YAHOO.widget.LogReader.prototype.fontSize = null;
/**
* Whether or not the footer UI is enabled for the log reader.
*
* @type boolean
*/
YAHOO.widget.LogReader.prototype.footerEnabled = true;
/**
* Whether or not output is compact (less readable).
*
* @type boolean
*/
YAHOO.widget.LogReader.prototype.compact = true;
/**
* Whether or not newest message is printed on top.
*
* @type boolean
*/
YAHOO.widget.LogReader.prototype.newestOnTop = true;
/***************************************************************************
* Public methods
***************************************************************************/
/**
* Pauses output of log messages. While paused, log messages are not lost, but
* get saved to a buffer and then output upon resume of log reader.
*/
YAHOO.widget.LogReader.prototype.pause = function() {
this._timeout = null;
this.logReaderEnabled = false;
};
/**
* Resumes output of log messages, including outputting any log messages that
* have been saved to buffer while paused.
*/
YAHOO.widget.LogReader.prototype.resume = function() {
this.logReaderEnabled = true;
this._printBuffer();
};
/**
* Hides UI of log reader. Logging functionality is not disrupted.
*/
YAHOO.widget.LogReader.prototype.hide = function() {
this._containerEl.style.display = "none";
};
/**
* Shows UI of log reader. Logging functionality is not disrupted.
*/
YAHOO.widget.LogReader.prototype.show = function() {
this._containerEl.style.display = "block";
};
/**
* Updates title to given string.
*
* @param {string} sTitle String to display in log reader's title bar.
*/
YAHOO.widget.LogReader.prototype.setTitle = function(sTitle) {
var regEx = />/g;
sTitle = sTitle.replace(regEx,">");
regEx = /</g;
sTitle = sTitle.replace(regEx,"<");
this._title.innerHTML = (sTitle);
};
/***************************************************************************
* Private members
***************************************************************************/
/**
* Internal class member to index multiple log reader instances.
*
* @type number
* @private
*/
YAHOO.widget.LogReader._index = 0;
/**
* A class member shared by all log readers 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.
*
* @type HTMLElement
* @private
*/
YAHOO.widget.LogReader._defaultContainerEl = null;
/**
* Buffer of log messages for batch output.
*
* @type array
* @private
*/
YAHOO.widget.LogReader.prototype._buffer = null;
/**
* Date of last output log message.
*
* @type date
* @private
*/
YAHOO.widget.LogReader.prototype._lastTime = null;
/**
* Batched output timeout ID.
*
* @type number
* @private
*/
YAHOO.widget.LogReader.prototype._timeout = null;
/**
* Array of filters for log message categories.
*
* @type array
* @private
*/
YAHOO.widget.LogReader.prototype._categoryFilters = null;
/**
* Array of filters for log message sources.
*
* @type array
* @private
*/
YAHOO.widget.LogReader.prototype._sourceFilters = null;
/**
* Log reader container element.
*
* @type HTMLElement
* @private
*/
YAHOO.widget.LogReader.prototype._containerEl = null;
/**
* Log reader header element.
*
* @type HTMLElement
* @private
*/
YAHOO.widget.LogReader.prototype._hdEl = null;
/**
* Log reader collapse element.
*
* @type HTMLElement
* @private
*/
YAHOO.widget.LogReader.prototype._collapseEl = null;
/**
* Log reader collapse button element.
*
* @type HTMLElement
* @private
*/
YAHOO.widget.LogReader.prototype._collapseBtn = null;
/**
* Log reader title header element.
*
* @type HTMLElement
* @private
*/
YAHOO.widget.LogReader.prototype._title = null;
/**
* Log reader console element.
*
* @type HTMLElement
* @private
*/
YAHOO.widget.LogReader.prototype._consoleEl = null;
/**
* Log reader footer element.
*
* @type HTMLElement
* @private
*/
YAHOO.widget.LogReader.prototype._ftEl = null;
/**
* Log reader buttons container element.
*
* @type HTMLElement
* @private
*/
YAHOO.widget.LogReader.prototype._btnsEl = null;
/**
* Container element for log reader category filter checkboxes.
*
* @type HTMLElement
* @private
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -