From 7fa04bb9e11be883b58258606a5cec765c25cbc9 Mon Sep 17 00:00:00 2001 From: "gavin%gavinsharp.com" Date: Tue, 29 Jan 2008 19:39:20 +0000 Subject: [PATCH] Bug 412990: Re-enable search service logging for opt builds (without the performance hit of checking the pref for each LOG call), r=mano, a=schrep git-svn-id: svn://10.0.0.236/trunk@244369 18797224-902f-48f8-a5cc-f745e15eee43 --- .../components/search/nsSearchService.js | 45 +++++++++++++++---- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/mozilla/browser/components/search/nsSearchService.js b/mozilla/browser/components/search/nsSearchService.js index ce7dae7454b..dcc430a4f1e 100755 --- a/mozilla/browser/components/search/nsSearchService.js +++ b/mozilla/browser/components/search/nsSearchService.js @@ -201,11 +201,21 @@ function isUsefulLine(aLine) { const SEARCH_LOG_PREFIX = "*** Search: "; /** - * Outputs aText to the JavaScript console as well as to stdout, if the search - * logging pref (browser.search.log) is set to true. + * Outputs aText to the JavaScript console as well as to stdout. */ -function LOG(aText) { +function DO_LOG(aText) { + dump(SEARCH_LOG_PREFIX + aText + "\n"); + var consoleService = Cc["@mozilla.org/consoleservice;1"]. + getService(Ci.nsIConsoleService); + consoleService.logStringMessage(aText); +} + #ifdef DEBUG +/** + * In debug builds, use a live, pref-based (browser.search.log) LOG function + * to allow enabling/disabling without a restart. + */ +function PREF_LOG(aText) { var prefB = Cc["@mozilla.org/preferences-service;1"]. getService(Ci.nsIPrefBranch); var shouldLog = false; @@ -214,13 +224,20 @@ function LOG(aText) { } catch (ex) {} if (shouldLog) { - dump(SEARCH_LOG_PREFIX + aText + "\n"); - var consoleService = Cc["@mozilla.org/consoleservice;1"]. - getService(Ci.nsIConsoleService); - consoleService.logStringMessage(aText); + DO_LOG(aText); } -#endif } +var LOG = PREF_LOG; + +#else + +/** + * Otherwise, don't log at all by default. This can be overridden at startup + * by the pref, see SearchService's _init method. + */ +var LOG = function(){}; + +#endif function ERROR(message, resultCode) { NS_ASSERT(false, SEARCH_LOG_PREFIX + message); @@ -2203,6 +2220,18 @@ SearchService.prototype = { _needToSetOrderPrefs: false, _init: function() { + var prefB = Cc["@mozilla.org/preferences-service;1"]. + getService(Ci.nsIPrefBranch); + var shouldLog = false; + try { + shouldLog = prefB.getBoolPref(BROWSER_SEARCH_PREF + "log"); + } catch (ex) {} + + if (shouldLog) { + // Replace the empty LOG function with the useful one + LOG = DO_LOG; + } + engineMetadataService.init(); engineUpdateService.init();