diff --git a/chrome/content/zotero/xpcom/debug.js b/chrome/content/zotero/xpcom/debug.js index 846fcf751a..854fe3aec6 100644 --- 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 index daa5e56980..0faf364952 100644 --- 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 index c3930fe19e..01f2972c4e 100644 --- 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);