Bug 831882 - Correctly install proxied log functions; r=rnewman
authorGregory Szorc <gps@mozilla.com>
Fri, 18 Jan 2013 10:11:28 -0800
changeset 129003 b4a8a77afe4052e567c169d90ab442d80ebdf465
parent 129002 fffc4af51c86adc5e28d8fe7831cbad2906a50ec
child 129004 8cc32d6fa70734e2a6a0689a13dec0207f365e2b
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs831882
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 831882 - Correctly install proxied log functions; r=rnewman
toolkit/modules/Sqlite.jsm
--- a/toolkit/modules/Sqlite.jsm
+++ b/toolkit/modules/Sqlite.jsm
@@ -142,29 +142,36 @@ function openConnection(options) {
  * @param basename
  *        (string) The basename of this database name. Used for logging.
  * @param number
  *        (Number) The connection number to this database.
  */
 function OpenedConnection(connection, basename, number) {
   let log = Log4Moz.repository.getLogger("Sqlite.Connection." + basename);
 
+  // getLogger() returns a shared object. We can't modify the functions on this
+  // object since they would have effect on all instances and last write would
+  // win. So, we create a "proxy" object with our custom functions. Everything
+  // else is proxied back to the shared logger instance via prototype
+  // inheritance.
+  let logProxy = {__proto__: log};
+
   // Automatically prefix all log messages with the identifier.
   for (let level in Log4Moz.Level) {
     if (level == "Desc") {
       continue;
     }
 
     let lc = level.toLowerCase();
-    log[lc] = function (msg) {
-      return Log4Moz.Logger.prototype[lc].call(log, "Conn #" + number + ": " + msg);
-    }
+    logProxy[lc] = function (msg) {
+      return log[lc].call(log, "Conn #" + number + ": " + msg);
+    };
   }
 
-  this._log = log;
+  this._log = logProxy;
 
   this._log.info("Opened");
 
   this._connection = connection;
   this._open = true;
 
   this._cachedStatements = new Map();
   this._anonymousStatements = new Map();