commit cbcf9cb3def4ead9d74dd49f1de273290d493988
parent f55c2f51ee0dde0b26f141e3e73f6263aebaff92
Author: Dan Stillman <dstillman@zotero.org>
Date: Fri, 2 Dec 2016 17:25:12 -0500
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.
Diffstat:
3 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/chrome/content/zotero/xpcom/debug.js b/chrome/content/zotero/xpcom/debug.js
@@ -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);
}
}
diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js
@@ -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();
diff --git a/defaults/preferences/zotero.js b/defaults/preferences/zotero.js
@@ -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);