fixed the resizable text area with IE problem fixed the ad space with IE problem merged the 7.2.0 and 7.1.4 change logs
457 lines
16 KiB
HTML
457 lines
16 KiB
HTML
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>JavaScript Documentation - Logger.js</title>
|
|
|
|
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<div id="header">
|
|
|
|
<h1>JavaScript Documentation</h1>
|
|
|
|
<h3><a href="./index.html">Logger</a></h3>
|
|
|
|
|
|
|
|
<div class="breadcrumbs">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a href="./index.html">Logger</a>
|
|
|
|
>
|
|
|
|
<strong>Logger.js</strong>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div id="body">
|
|
|
|
|
|
|
|
|
|
|
|
<div class="nav">
|
|
|
|
<div class="module resources">
|
|
|
|
<ul class="content">
|
|
|
|
<li><a href="overview-tree.html">Tree View</a></li>
|
|
|
|
<li><a href="index-all.html">Element Index</a></li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="module">
|
|
|
|
<h4><a href="./allclasses-noframe.html">Classes</a></h4>
|
|
|
|
<ul class="content">
|
|
|
|
|
|
|
|
<li>
|
|
|
|
<a href="YAHOO.widget.html">
|
|
|
|
YAHOO.widget</a>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
<li>
|
|
|
|
<a href="YAHOO.widget.LogReader.html">
|
|
|
|
YAHOO.widget.LogReader</a>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
<li>
|
|
|
|
<a href="YAHOO.widget.LogWriter.html">
|
|
|
|
YAHOO.widget.LogWriter</a>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="module">
|
|
|
|
<h4><a href="./overview-summary.html">Files</a></h4>
|
|
|
|
<ul class="content">
|
|
|
|
|
|
|
|
<li>
|
|
|
|
<a href="overview-summary-Logger.js.html">
|
|
|
|
Logger.js</a>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
<li>
|
|
|
|
<a href="overview-summary-LogReader.js.html">
|
|
|
|
LogReader.js</a>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
<li>
|
|
|
|
<a href="overview-summary-LogWriter.js.html">
|
|
|
|
LogWriter.js</a>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="main">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2>Logger.js</h2>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="meta">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="section source">
|
|
|
|
<h3><a name="source">Souce Code</a> <span class="top">[<a href="#top">top</a>]</span></h3>
|
|
|
|
<pre class="sourceview"><span class="comment">/****************************************************************************/</span>
|
|
|
|
<span class="comment">/****************************************************************************/</span>
|
|
|
|
<span class="comment">/****************************************************************************/</span>
|
|
|
|
<span class="comment">/**
|
|
|
|
* Singleton providing core logging functionality. Saves logs written through the
|
|
|
|
* global YAHOO.log function or written by LogWriter. Provides access to logs
|
|
|
|
* for reading by LogReader. Log messages are automatically output to Firebug,
|
|
|
|
* if present.
|
|
|
|
*
|
|
|
|
* requires YAHOO.util.Event Event utility
|
|
|
|
*/</span>
|
|
|
|
YAHOO.widget.Logger = {
|
|
|
|
<span class="comment"> // Initialize members</span>
|
|
|
|
loggerEnabled: true,
|
|
|
|
_browserConsoleEnabled: true,
|
|
|
|
categories: [<span class="literal">"info"</span>,<span class="literal">"warn"</span>,<span class="literal">"error"</span>,<span class="literal">"time"</span>,<span class="literal">"window"</span>],
|
|
|
|
sources: [<span class="literal">"global"</span>],
|
|
|
|
_stack: [], // holds all log msgs
|
|
|
|
maxStackEntries: 2500,
|
|
|
|
_startTime: new Date().getTime(), // static start timestamp
|
|
|
|
_lastTime: null // timestamp of last logged message
|
|
|
|
};
|
|
|
|
|
|
|
|
<span class="comment">/***************************************************************************
|
|
|
|
* Events
|
|
|
|
***************************************************************************/</span>
|
|
|
|
<span class="comment">/**
|
|
|
|
* Fired when a new category has been created. Subscribers receive the following
|
|
|
|
* array:<br>
|
|
|
|
* - args[0] The category name
|
|
|
|
*/</span>
|
|
|
|
YAHOO.widget.Logger.categoryCreateEvent = new YAHOO.util.CustomEvent(<span class="literal">"categoryCreate"</span>, <span class="reserved">this</span>, true);
|
|
|
|
|
|
|
|
<span class="comment">/**
|
|
|
|
* Fired when a new source has been named. Subscribers receive the following
|
|
|
|
* array:<br>
|
|
|
|
* - args[0] The source name
|
|
|
|
*/</span>
|
|
|
|
YAHOO.widget.Logger.sourceCreateEvent = new YAHOO.util.CustomEvent(<span class="literal">"sourceCreate"</span>, <span class="reserved">this</span>, true);
|
|
|
|
|
|
|
|
<span class="comment">/**
|
|
|
|
* Fired when a new log message has been created. Subscribers receive the
|
|
|
|
* following array:<br>
|
|
|
|
* - args[0] The log message
|
|
|
|
*/</span>
|
|
|
|
YAHOO.widget.Logger.newLogEvent = new YAHOO.util.CustomEvent(<span class="literal">"newLog"</span>, <span class="reserved">this</span>, true);
|
|
|
|
|
|
|
|
<span class="comment">/**
|
|
|
|
* Fired when the Logger has been reset has been created.
|
|
|
|
*/</span>
|
|
|
|
YAHOO.widget.Logger.logResetEvent = new YAHOO.util.CustomEvent(<span class="literal">"logReset"</span>, <span class="reserved">this</span>, true);
|
|
|
|
|
|
|
|
<span class="comment">/***************************************************************************
|
|
|
|
* Public methods
|
|
|
|
***************************************************************************/</span>
|
|
|
|
<span class="comment">/**
|
|
|
|
* Saves a log message to the stack and fires newLogEvent. If the log message is
|
|
|
|
* assigned to an unknown category, creates a new category. If the log message is
|
|
|
|
* from an unknown source, creates a new source. If Firebug is enabled,
|
|
|
|
* outputs the log message to Firebug.
|
|
|
|
*
|
|
|
|
* <span class="attrib">@param</span> {string} sMsg The log message
|
|
|
|
* <span class="attrib">@param</span> {string} sCategory Category of log message, or null
|
|
|
|
* <span class="attrib">@param</span> {string} sSource Source of LogWriter, or null if global
|
|
|
|
*/</span>
|
|
|
|
YAHOO.widget.Logger.log = <span class="reserved">function</span>(sMsg, sCategory, sSource) {
|
|
|
|
<span class="reserved">if</span>(<span class="reserved">this</span>.loggerEnabled) {
|
|
|
|
<span class="reserved">if</span>(!sCategory) {
|
|
|
|
sCategory = <span class="literal">"info"</span>; // default category
|
|
|
|
}
|
|
|
|
<span class="reserved">else</span> <span class="reserved">if</span>(<span class="reserved">this</span>._isNewCategory(sCategory)) {
|
|
|
|
<span class="reserved">this</span>._createNewCategory(sCategory);
|
|
|
|
}
|
|
|
|
var sClass = <span class="literal">"global"</span>; // default source
|
|
|
|
var sDetail = null;
|
|
|
|
<span class="reserved">if</span>(sSource) {
|
|
|
|
var spaceIndex = sSource.indexOf(<span class="literal">" "</span>);
|
|
|
|
<span class="reserved">if</span>(spaceIndex > 0) {
|
|
|
|
sClass = sSource.substring(0,spaceIndex);// substring until first space
|
|
|
|
sDetail = sSource.substring(spaceIndex,sSource.length);// the rest of the source
|
|
|
|
}
|
|
|
|
<span class="reserved">else</span> {
|
|
|
|
sClass = sSource;
|
|
|
|
}
|
|
|
|
<span class="reserved">if</span>(<span class="reserved">this</span>._isNewSource(sClass)) {
|
|
|
|
<span class="reserved">this</span>._createNewSource(sClass);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var timestamp = new Date();
|
|
|
|
var logEntry = {
|
|
|
|
time: timestamp,
|
|
|
|
category: sCategory,
|
|
|
|
source: sClass,
|
|
|
|
sourceDetail: sDetail,
|
|
|
|
msg: sMsg
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var stack = <span class="reserved">this</span>._stack;
|
|
|
|
var maxStackEntries = <span class="reserved">this</span>.maxStackEntries;
|
|
|
|
<span class="reserved">if</span>(maxStackEntries && !isNaN(maxStackEntries) && (stack.length >= maxStackEntries)) {
|
|
|
|
stack.shift();
|
|
|
|
}
|
|
|
|
stack.push(logEntry);
|
|
|
|
<span class="reserved">this</span>.newLogEvent.fire(logEntry);
|
|
|
|
|
|
|
|
<span class="reserved">if</span>(<span class="reserved">this</span>._browserConsoleEnabled) {
|
|
|
|
<span class="reserved">this</span>._printToBrowserConsole(logEntry);
|
|
|
|
}
|
|
|
|
<span class="reserved">return</span> true;
|
|
|
|
}
|
|
|
|
<span class="reserved">else</span> {
|
|
|
|
<span class="reserved">return</span> false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
<span class="comment">/**
|
|
|
|
* Resets internal stack and startTime, enables Logger, and fires logResetEvent.
|
|
|
|
*
|
|
|
|
*/</span>
|
|
|
|
YAHOO.widget.Logger.reset = <span class="reserved">function</span>() {
|
|
|
|
<span class="reserved">this</span>._stack = [];
|
|
|
|
<span class="reserved">this</span>._startTime = new Date().getTime();
|
|
|
|
<span class="reserved">this</span>.loggerEnabled = true;
|
|
|
|
<span class="reserved">this</span>.log(null, <span class="literal">"Logger reset"</span>);
|
|
|
|
<span class="reserved">this</span>.logResetEvent.fire();
|
|
|
|
};
|
|
|
|
|
|
|
|
<span class="comment">/**
|
|
|
|
* Public accessor to internal stack of log messages.
|
|
|
|
*
|
|
|
|
* <span class="attrib">@return</span> {array} Array of log messages.
|
|
|
|
*/</span>
|
|
|
|
YAHOO.widget.Logger.getStack = <span class="reserved">function</span>() {
|
|
|
|
<span class="reserved">return</span> <span class="reserved">this</span>._stack;
|
|
|
|
};
|
|
|
|
|
|
|
|
<span class="comment">/**
|
|
|
|
* Public accessor to internal start time.
|
|
|
|
*
|
|
|
|
* <span class="attrib">@return</span> {date} Internal date of when Logger singleton was initialized.
|
|
|
|
*/</span>
|
|
|
|
YAHOO.widget.Logger.getStartTime = <span class="reserved">function</span>() {
|
|
|
|
<span class="reserved">return</span> <span class="reserved">this</span>._startTime;
|
|
|
|
};
|
|
|
|
|
|
|
|
<span class="comment">/**
|
|
|
|
* Disables output to the browser's global console.log() function, which is used
|
|
|
|
* by the Firebug extension to Firefox as well as Safari.
|
|
|
|
*/</span>
|
|
|
|
YAHOO.widget.Logger.disableBrowserConsole = <span class="reserved">function</span>() {
|
|
|
|
YAHOO.log(<span class="literal">"Logger output to the function console.log() has been disabled."</span>);
|
|
|
|
<span class="reserved">this</span>._browserConsoleEnabled = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
<span class="comment">/**
|
|
|
|
* Enables output to the browser's global console.log() function, which is used
|
|
|
|
* by the Firebug extension to Firefox as well as Safari.
|
|
|
|
*/</span>
|
|
|
|
YAHOO.widget.Logger.enableBrowserConsole = <span class="reserved">function</span>() {
|
|
|
|
<span class="reserved">this</span>._browserConsoleEnabled = true;
|
|
|
|
YAHOO.log(<span class="literal">"Logger output to the function console.log() has been enabled."</span>);
|
|
|
|
};
|
|
|
|
|
|
|
|
<span class="comment">/***************************************************************************
|
|
|
|
* Private methods
|
|
|
|
***************************************************************************/</span>
|
|
|
|
<span class="comment">/**
|
|
|
|
* Creates a new category of log messages and fires categoryCreateEvent.
|
|
|
|
*
|
|
|
|
* <span class="attrib">@param</span> {string} category Category name
|
|
|
|
* <span class="attrib">@private</span>
|
|
|
|
*/</span>
|
|
|
|
YAHOO.widget.Logger._createNewCategory = <span class="reserved">function</span>(category) {
|
|
|
|
<span class="reserved">this</span>.categories.push(category);
|
|
|
|
<span class="reserved">this</span>.categoryCreateEvent.fire(category);
|
|
|
|
};
|
|
|
|
|
|
|
|
<span class="comment">/**
|
|
|
|
* Checks to see if a category has already been created.
|
|
|
|
*
|
|
|
|
* <span class="attrib">@param</span> {string} category Category name
|
|
|
|
* <span class="attrib">@return</span> {boolean} Returns true if category is unknown, else returns false
|
|
|
|
* <span class="attrib">@private</span>
|
|
|
|
*/</span>
|
|
|
|
YAHOO.widget.Logger._isNewCategory = <span class="reserved">function</span>(category) {
|
|
|
|
<span class="reserved">for</span>(var i=0; i < <span class="reserved">this</span>.categories.length; i++) {
|
|
|
|
<span class="reserved">if</span>(category == <span class="reserved">this</span>.categories[i]) {
|
|
|
|
<span class="reserved">return</span> false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
<span class="reserved">return</span> true;
|
|
|
|
};
|
|
|
|
|
|
|
|
<span class="comment">/**
|
|
|
|
* Creates a new source of log messages and fires sourceCreateEvent.
|
|
|
|
*
|
|
|
|
* <span class="attrib">@param</span> {string} source Source name
|
|
|
|
* <span class="attrib">@private</span>
|
|
|
|
*/</span>
|
|
|
|
YAHOO.widget.Logger._createNewSource = <span class="reserved">function</span>(source) {
|
|
|
|
<span class="reserved">this</span>.sources.push(source);
|
|
|
|
<span class="reserved">this</span>.sourceCreateEvent.fire(source);
|
|
|
|
};
|
|
|
|
|
|
|
|
<span class="comment">/**
|
|
|
|
* Checks to see if a source has already been created.
|
|
|
|
*
|
|
|
|
* <span class="attrib">@param</span> {string} source Source name
|
|
|
|
* <span class="attrib">@return</span> {boolean} Returns true if source is unknown, else returns false
|
|
|
|
* <span class="attrib">@private</span>
|
|
|
|
*/</span>
|
|
|
|
YAHOO.widget.Logger._isNewSource = <span class="reserved">function</span>(source) {
|
|
|
|
<span class="reserved">if</span>(source) {
|
|
|
|
<span class="reserved">for</span>(var i=0; i < <span class="reserved">this</span>.sources.length; i++) {
|
|
|
|
<span class="reserved">if</span>(source == <span class="reserved">this</span>.sources[i]) {
|
|
|
|
<span class="reserved">return</span> false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
<span class="reserved">return</span> true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
<span class="comment">/**
|
|
|
|
* Outputs a log message to Firebug.
|
|
|
|
*
|
|
|
|
* <span class="attrib">@param</span> {object} entry Log entry object
|
|
|
|
* <span class="attrib">@private</span>
|
|
|
|
*/</span>
|
|
|
|
YAHOO.widget.Logger._printToBrowserConsole = <span class="reserved">function</span>(entry) {
|
|
|
|
<span class="reserved">if</span>(window.console && console.log) {
|
|
|
|
var category = entry.category;
|
|
|
|
var label = entry.category.substring(0,4).toUpperCase();
|
|
|
|
|
|
|
|
var time = entry.time;
|
|
|
|
<span class="reserved">if</span> (time.toLocaleTimeString) {
|
|
|
|
var localTime = time.toLocaleTimeString();
|
|
|
|
}
|
|
|
|
<span class="reserved">else</span> {
|
|
|
|
localTime = time.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
var msecs = time.getTime();
|
|
|
|
var elapsedTime = (YAHOO.widget.Logger._lastTime) ?
|
|
|
|
(msecs - YAHOO.widget.Logger._lastTime) : 0;
|
|
|
|
YAHOO.widget.Logger._lastTime = msecs;
|
|
|
|
|
|
|
|
var output = <span class="comment">//Firebug doesn't support HTML "<span class='"+category+"'>"+label+"</span> " +</span>
|
|
|
|
localTime + " (" +
|
|
|
|
elapsedTime + "ms): " +
|
|
|
|
entry.source + ": " +
|
|
|
|
entry.msg;
|
|
|
|
|
|
|
|
|
|
|
|
console.log(output);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* Private event handlers
|
|
|
|
***************************************************************************/
|
|
|
|
/**
|
|
|
|
* Handles logging of messages due to window error events.
|
|
|
|
*
|
|
|
|
* @param {string} msg The error message
|
|
|
|
* @param {string} url URL of the error
|
|
|
|
* @param {string} line Line number of the error
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
YAHOO.widget.Logger._onWindowError = function(msg,url,line) {
|
|
|
|
// Logger is not in scope of this event handler
|
|
|
|
try {
|
|
|
|
YAHOO.widget.Logger.log(msg+'</span> (<span class="literal">'+url+'</span>, line <span class="literal">'+line+'</span>)', <span class="literal">"window"</span>);
|
|
|
|
<span class="reserved">if</span>(YAHOO.widget.Logger._origOnWindowError) {
|
|
|
|
YAHOO.widget.Logger._origOnWindowError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
<span class="reserved">return</span> false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
<span class="comment">/**
|
|
|
|
* Handle native JavaScript errors
|
|
|
|
*/</span>
|
|
|
|
<span class="comment">//NB: Not all browsers support the window.onerror event</span>
|
|
|
|
<span class="reserved">if</span>(window.onerror) {
|
|
|
|
<span class="comment"> // Save any previously defined handler to call</span>
|
|
|
|
YAHOO.widget.Logger._origOnWindowError = window.onerror;
|
|
|
|
}
|
|
|
|
window.onerror = YAHOO.widget.Logger._onWindowError;
|
|
|
|
|
|
|
|
<span class="comment">/**
|
|
|
|
* First log
|
|
|
|
*/</span>
|
|
|
|
YAHOO.widget.Logger.log(<span class="literal">"Logger initialized"</span>);
|
|
|
|
|
|
|
|
</pre>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div id="footer">
|
|
|
|
<hr />
|
|
|
|
Copyright © 2006 Yahoo! Inc. All rights reserved.
|
|
|
|
<br />
|
|
|
|
Documentation generated by <a href="http://jsdoc.sourceforge.net/">JSDoc</a>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|