Expose debug level, and tie etemplate2 profiling to debug level 4 - Log

This commit is contained in:
Nathan Gray 2015-08-25 16:19:40 +00:00
parent 62966084ff
commit 56a595dc57
2 changed files with 35 additions and 22 deletions

View File

@ -355,19 +355,26 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback)
// Register a handler for AJAX responses // Register a handler for AJAX responses
egw(currentapp, window).registerJSONPlugin(etemplate2_handle_assign, this, 'assign'); egw(currentapp, window).registerJSONPlugin(etemplate2_handle_assign, this, 'assign');
if(console.groupCollapsed) if(egw.debug_level() >= 3)
{ {
egw.window.console.groupCollapsed("Loading %s into ", _name, '#'+this.DOMContainer.id); if(console.groupCollapsed)
{
egw.window.console.groupCollapsed("Loading %s into ", _name, '#'+this.DOMContainer.id);
}
} }
if(console.time) // Timing & profiling on debug level 'log' (4)
if(egw.debug_level() >= 4)
{ {
console.time(_name); if(console.time)
{
console.time(_name);
}
if(console.profile)
{
console.profile(_name);
}
var start_time = (new Date).getTime();
} }
if(console.profile)
{
console.profile(_name);
}
var start_time = (new Date).getTime();
// require necessary translations from server, if not already loaded // require necessary translations from server, if not already loaded
if (!$j.isArray(_data.langRequire)) _data.langRequire = []; if (!$j.isArray(_data.langRequire)) _data.langRequire = [];
@ -434,7 +441,7 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback)
var _load = function() { var _load = function() {
egw.debug("log", "Loading template..."); egw.debug("log", "Loading template...");
if(console.timeStamp) if(egw.debug_level() >= 4 && console.timeStamp)
{ {
console.timeStamp("Begin rendering template"); console.timeStamp("Begin rendering template");
} }
@ -462,7 +469,7 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback)
// Insert the document fragment to the DOM Container // Insert the document fragment to the DOM Container
this.DOMContainer.appendChild(frag); this.DOMContainer.appendChild(frag);
if(console.groupEnd) if(egw.debug_level >= 3 && console.groupEnd)
{ {
egw.window.console.groupEnd(); egw.window.console.groupEnd();
} }
@ -524,19 +531,22 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback)
$j(this.DOMContainer).trigger('load', this); $j(this.DOMContainer).trigger('load', this);
// Profiling // Profiling
if(console.timeEnd) if(egw.debug_level() >= 4)
{ {
console.timeEnd(_name); if(console.timeEnd)
{
console.timeEnd(_name);
}
if(console.profileEnd)
{
console.profileEnd(_name);
}
var end_time = (new Date).getTime();
var gen_time_div = $j('#divGenTime_'+appname);
if (!gen_time_div.length) gen_time_div = $j('.pageGenTime');
gen_time_div.find('.et2RenderTime').remove();
gen_time_div.append('<span class="et2RenderTime">'+egw.lang('eT2 rendering took %1s', (end_time-start_time)/1000)+'</span>');
} }
if(console.profileEnd)
{
console.profileEnd(_name);
}
var end_time = (new Date).getTime();
var gen_time_div = $j('#divGenTime_'+appname);
if (!gen_time_div.length) gen_time_div = $j('.pageGenTime');
gen_time_div.find('.et2RenderTime').remove();
gen_time_div.append('<span class="et2RenderTime">'+egw.lang('eT2 rendering took %1s', (end_time-start_time)/1000)+'</span>');
},this)); },this));
}; };

View File

@ -315,6 +315,9 @@ egw.extend('debug', egw.MODULE_GLOBAL, function(_app, _wnd) {
* console function. * console function.
*/ */
return { return {
debug_level: function() {
return DEBUGLEVEL;
},
debug: function(_level) { debug: function(_level) {
if (typeof _wnd.console != "undefined") if (typeof _wnd.console != "undefined")
{ {