console-debug.js revision 5ccd4c3147ccd31c3c6ecf320f7e7c2328a24531
/**
* LogReader creates a visualization for Y.log statements. Log messages
* include a category such as "info" or "warn", a source, and various timing
* info. Messages are rendered to the Reader in asynchronous buffered batches
* so as to avoid interfering with the operation of your page.
*
* @class LogReader
* @extends Widget
*/
LOGREADER = 'logreader',
ENTRY = 'entry',
RESET = 'reset',
CHECKED = 'checked',
CLEAR = 'clear',
PAUSE = 'pause',
PAUSED = 'paused',
INFO = 'info',
WARN = 'warn',
ERROR = 'error',
INNER_HTML = 'innerHTML',
UI = 'ui',
CLICK = 'click',
CONTENT_BOX = 'contentBox',
RE_AMP = /&/g,
RE_LT = /</g,
RE_GT = />/g,
RE_INLINE_SOURCE = /^(\S+)\s/,
ESC_AMP = '&',
ESC_LT = '<',
ESC_GT = '>',
L = Y.Lang,
// Here for defaulting in ATTRS.entryTemplate.value
'<p>'+
'{label}</span>'+
' {totalTime}ms (+{elapsedTime}) {localTime}:'+
'</span>'+
'</p>'+
'{sourceAndDetail}'+
'</p>'+
'</div>'+
'</pre>';
function LogReader() {
}
/**
* The identity of the widget.
*
* @property LogReader.NAME
* @type String
* @static
*/
LOG_LEVEL_INFO : 3,
LOG_LEVEL_WARN : 2,
LOG_LEVEL_ERROR : 1,
'<input type="checkbox" class="'+
'</label>' +
'</div>'+
'</div>',
ATTRS : {
/**
* Strings used in the LogReader UI. Default locale en-us.
*
* @attribute strings
* @type Object
*/
strings : {
value : {
PAUSE : "Pause",
CLEAR : "Clear"
}
},
/**
* Title appearing in the head of the LogReader console.
*
* @attribute title
* @type String
* @default "Log Console"
*/
title : {
value : "Log Console",
},
/**
* Boolean to pause the outputting of new messages to the console.
* When paused, messages will accumulate in the buffer.
*
* @attribute paused
* @type boolean
* @default false
*/
paused : {
value : false,
},
/**
* If a category is not specified in the Y.log(..) statement, this
* category will be used.
*
* @attribute defaultCategory
* @type String
* @default "info"
*/
defaultCategory : {
},
/**
* If a source is not specified in the Y.log(..) statement, this
* source will be used.
*
* @attribute defaultSource
* @type String
* @default "global"
*/
defaultSource : {
value : 'global',
},
/**
* The markup template to use to render log entries. Bracketed
* placeholders {likeThis} will be replaced with the appropriate data
* from the entry object.
*
* @attribute entryTemplate
* @type String
* @deafult (see LogReader.ENTRY_TEMPLATE)
*/
entryTemplate : {
},
logLevel : {
validator : function (v) {
return this._validateLogLevel(v);
},
set : function (v) {
return this._setLogLevel(v);
}
},
printTimeout : {
value : 100,
},
consoleLimit : {
value : 500,
},
newestOnTop : {
value : true
},
startTime : {
value : new Date()
},
lastTime : {
value : new Date()
}
}
});
_title : null,
_console : null,
_foot : null,
_timeout : null,
buffer : null,
// API methods
clearConsole : function () {
// TODO: clear event listeners from console contents
if (this._timeout) {
clearTimeout(this._timeout);
this._timeout = null;
}
this.buffer = [];
},
reset : function () {
},
printBuffer: function () {
// Called from timeout, so calls to Y.log will not be caught by the
// recursion protection in event. Turn off logging while printing.
Y.debug = false;
clearTimeout(this._timeout);
this._timeout = null;
i,len;
this.buffer = [];
// TODO: use doc frag?
this.printLogEntry(messages[i]);
this._trimOldEntries();
}
}
},
printLogEntry : function (m) {
m = this._htmlEscapeMessage(m);
this._addToConsole(n);
},
// Widget core methods
initializer : function (cfg) {
this.buffer = [];
},
renderUI : function () {
this._initHead();
this._initConsole();
this._initFoot();
},
syncUI : function () {
},
bindUI : function () {
// Attribute changes
},
// Support methods
_initHead : function () {
var n = this.get(CONTENT_BOX),
head;
},
_initConsole : function () {
this._foot || null);
},
_initFoot : function () {
var S = this.getStrings(), nodes;
if (nodes) {
}
if (nodes) {
}
},
},
var m = {
time : new Date(),
source : null,
label : null,
localTime : null,
elapsedTime : null,
totalTime : null
};
// Extract m.source "Foo" from m.sourceAndDetail "Foo bar baz"
RegExp.$1 : m.sourceAndDetail;
return m;
},
_schedulePrint : function () {
this._timeout = setTimeout(
Y.bind(this.printBuffer,this),
this.get('printTimeout'));
}
},
_addToConsole : function (node) {
if (!toTop) {
}
},
_htmlEscapeMessage : function (m) {
m = Y.clone(m);
return m;
},
_trimOldEntries : function () {
if (this._console) {
if (i > 0) {
if (this.get('newestOnTop')) {
}
} else {
for (;i>=0;--i) {
}
}
}
}
},
_escapeHTML : function (s) {
return isString(s) ?
s;
},
// DOM event handlers
_onPauseClick : function (e) {
// TODO: label click cause problems?
},
// Attribute setters and validators
_setLogLevel : function (v) {
if (isString(v)) {
v = v.toLowerCase();
v = v === ERROR ?
v === WARN ?
} else if (!isNumber(v)) {
v = LogReader.LOG_LEVEL_INFO;
}
return v;
},
_validateLogLevel : function (v) {
return v === LogReader.LOG_LEVEL_INFO ||
v === LogReader.LOG_LEVEL_WARN ||
v === LogReader.LOG_LEVEL_ERROR;
},
// Attribute event handlers
_afterTitleChange : function (e) {
},
_afterPausedChange : function (e) {
}
if (!paused) {
this._schedulePrint();
} else if (this._timeout) {
clearTimeout(this._timeout);
this._timeout = null;
}
},
_afterConsoleLimitChange : function () {
this._trimOldEntries();
},
// Custom event listeners and default functions
});
}
},
_defResetFn : function () {
this.clearConsole();
this.set('startTime',new Date());
this.set('disabled',false);
},
_defEntryFn : function (e) {
if (e.message) {
this._schedulePrint();
}
}
});