Color long time intervals red in debug output to terminal

Defaults to 250 ms. The threshold can be changed with
extensions.zotero.debug.slowTime. Set to 0 to disable.
This commit is contained in:
Dan Stillman 2016-12-02 17:25:12 -05:00
parent f55c2f51ee
commit cbcf9cb3de
3 changed files with 27 additions and 6 deletions

View file

@ -26,10 +26,20 @@
Zotero.Debug = new function () {
var _console, _consolePref, _stackTrace, _store, _level, _lastTime, _output = [];
var _slowTime = false;
var _colorOutput = false;
this.init = function (forceDebugLog) {
_consolePref = Zotero.Prefs.get('debug.log');
_console = _consolePref || forceDebugLog;
if (_console && Zotero.isFx && !Zotero.isBookmarklet && (!Zotero.isWin || _consolePref)) {
_colorOutput = true;
}
if (_colorOutput) {
// Time threshold in milliseconds above which intervals
// should be colored red in terminal output
_slowTime = Zotero.Prefs.get('debug.log.slowTime');
}
_store = Zotero.Prefs.get('debug.store');
if (_store) {
Zotero.Prefs.set('debug.store', false);
@ -60,18 +70,29 @@ Zotero.Debug = new function () {
}
var deltaStr = '';
var deltaStrStore = '';
var delta = 0;
var d = new Date();
if (_lastTime) {
delta = d - _lastTime;
}
_lastTime = d;
var slowPrefix = "";
var slowSuffix = "";
if (_slowTime && delta > _slowTime) {
slowPrefix = "\033[31;40m";
slowSuffix = "\033[0m";
}
// TODO: Replace with String.prototype.padStart once available (Fx48)
while (("" + delta).length < 7) {
delta = '0' + delta;
}
deltaStr = '(+' + delta + ')';
deltaStr = "(" + slowPrefix + "+" + delta + slowSuffix + ")";
if (_store) {
deltaStrStore = "(+" + delta + ")";
}
if (stack === true) {
// Display stack starting from where this was called
@ -121,7 +142,7 @@ Zotero.Debug = new function () {
_output.splice(0, Math.abs(overage));
}
}
_output.push('(' + level + ')' + deltaStr + ': ' + message);
_output.push('(' + level + ')' + deltaStrStore + ': ' + message);
}
}

View file

@ -174,10 +174,6 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
}
};
// Load in the preferences branch for the extension
Zotero.Prefs.init();
Zotero.Debug.init(options && options.forceDebugLog);
if (options) {
let opts = [
'openPane',
@ -271,6 +267,9 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
}
Zotero.rtl = Zotero.dir == 'rtl';
Zotero.Prefs.init();
Zotero.Debug.init(options && options.forceDebugLog);
// Make sure that Zotero Standalone is not running as root
if(Zotero.isStandalone && !Zotero.isWin) _checkRoot();

View file

@ -12,6 +12,7 @@ pref("extensions.zotero.useDataDir", false);
pref("extensions.zotero.dataDir", '');
pref("extensions.zotero.warnOnUnsafeDataDir", true);
pref("extensions.zotero.debug.log",false);
pref("extensions.zotero.debug.log.slowTime", 250);
pref("extensions.zotero.debug.stackTrace", false);
pref("extensions.zotero.debug.store",false);
pref("extensions.zotero.debug.store.limit",500000);