Add preference to put stack traces in debug output

This commit is contained in:
Simon Kornblith 2011-08-29 23:11:19 +00:00
parent 440d692d33
commit 3c0e11121f
2 changed files with 14 additions and 7 deletions

View file

@ -28,13 +28,7 @@ Zotero.Debug = new function () {
this.__defineGetter__('storing', function () { return _store; }); this.__defineGetter__('storing', function () { return _store; });
this.__defineGetter__('enabled', function () { return _console || _store; }); this.__defineGetter__('enabled', function () { return _console || _store; });
var _console; var _console, _stackTrace, _store, _level, _time, _lastTime, _output = [];
var _store;
var _level;
var _time;
var _lastTime;
var _output = [];
this.init = function () { this.init = function () {
_console = Zotero.Prefs.get('debug.log'); _console = Zotero.Prefs.get('debug.log');
@ -44,6 +38,7 @@ Zotero.Debug = new function () {
} }
_level = Zotero.Prefs.get('debug.level'); _level = Zotero.Prefs.get('debug.level');
_time = Zotero.Prefs.get('debug.time'); _time = Zotero.Prefs.get('debug.time');
_stackTrace = Zotero.Prefs.get('debug.stackTrace');
} }
this.log = function (message, level) { this.log = function (message, level) {
@ -80,6 +75,17 @@ Zotero.Debug = new function () {
deltaStr = '(+' + delta + ')'; deltaStr = '(+' + delta + ')';
} }
if (_stackTrace) {
var stack = (new Error()).stack;
var nl1Index = stack.indexOf("\n")
var nl2Index = stack.indexOf("\n", nl1Index+1);
var line2 = stack.substring(nl1Index+2, nl2Index-1);
var debugLine = line2.substr(line2.indexOf("@"));
stack = stack.substring(nl2Index, stack.length-1);
message += "\n"+debugLine+stack;
}
if (_console) { if (_console) {
var output = 'zotero(' + level + ')' + (_time ? deltaStr : '') + ': ' + message; var output = 'zotero(' + level + ')' + (_time ? deltaStr : '') + ': ' + message;
if(Zotero.isFx) { if(Zotero.isFx) {

View file

@ -11,6 +11,7 @@ pref("extensions.zotero.dataDir", '');
pref("extensions.zotero.lastDataDir", ''); pref("extensions.zotero.lastDataDir", '');
pref("extensions.zotero.dbLockExclusive", true); pref("extensions.zotero.dbLockExclusive", true);
pref("extensions.zotero.debug.log",false); pref("extensions.zotero.debug.log",false);
pref("extensions.zotero.debug.stackTrace", false);
pref("extensions.zotero.debug.store",false); pref("extensions.zotero.debug.store",false);
pref("extensions.zotero.debug.store.limit",750000); pref("extensions.zotero.debug.store.limit",750000);
pref("extensions.zotero.debug.level",5); pref("extensions.zotero.debug.level",5);