Merged changes
authorjonathandicarlo@jonathan-dicarlos-macbook-pro.local
Fri, 30 May 2008 11:11:02 -0700
changeset 44492 d11284c8ad1c3b30a4d7ad8e31b6efb2c563c7a9
parent 44491 7e0928fd9666f7ce5a615560b02667671adba875 (current diff)
parent 44489 1fad1f16ec3dcc44659930efa9357f32c76d49eb (diff)
child 44493 7f2fff853b79710d4f81a73f3dfa60940af688b3
push idunknown
push userunknown
push dateunknown
Merged changes
--- a/services/sync/modules/log4moz.js
+++ b/services/sync/modules/log4moz.js
@@ -79,17 +79,25 @@ let Log4Moz = {
       0:  "ALL"
     }
   },
 
   get Service() {
     delete Log4Moz.Service;
     Log4Moz.Service = new Log4MozService();
     return Log4Moz.Service;
-  }
+  },
+
+  get Formatter() { return Formatter; },
+  get BasicFormatter() { return BasicFormatter; },
+  get Appender() { return Appender; },
+  get DumpAppender() { return DumpAppender; },
+  get ConsoleAppender() { return ConsoleAppender; },
+  get FileAppender() { return FileAppender; },
+  get RotatingFileAppender() { return RotatingFileAppender; }
 };
 
 
 /*
  * LogMessage
  * Encapsulates a single log event's data
  */
 function LogMessage(loggerName, level, message){
@@ -407,16 +415,22 @@ FileAppender.prototype = {
 FileAppender.prototype.__proto__ = new Appender();
 
 /*
  * RotatingFileAppender
  * Similar to FileAppender, but rotates logs when they become too large
  */
 
 function RotatingFileAppender(file, formatter, maxSize, maxBackups) {
+  if (maxSize === undefined)
+    maxSize = ONE_MEGABYTE * 2;
+
+  if (maxBackups === undefined)
+    maxBackups = 0;
+
   this._name = "RotatingFileAppender";
   this._file = file; // nsIFile
   this._formatter = formatter;
   this._maxSize = maxSize;
   this._maxBackups = maxBackups;
 }
 RotatingFileAppender.prototype = {
   doAppend: function RFApp_doAppend(message) {
@@ -466,45 +480,10 @@ Log4MozService.prototype = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]),
 
   get rootLogger() {
     return this._repository.rootLogger;
   },
 
   getLogger: function LogSvc_getLogger(name) {
     return this._repository.getLogger(name);
-  },
-
-  newAppender: function LogSvc_newAppender(kind, formatter) {
-    switch (kind) {
-    case "dump":
-      return new DumpAppender(formatter);
-    case "console":
-      return new ConsoleAppender(formatter);
-    default:
-      dump("log4moz: unknown appender kind: " + kind);
-      return;
-    }
-  },
-
-  newFileAppender: function LogSvc_newAppender(kind, file, formatter) {
-    switch (kind) {
-    case "file":
-      return new FileAppender(file, formatter);
-    case "rotating":
-      // FIXME: hardcoded constants
-      return new RotatingFileAppender(file, formatter, ONE_MEGABYTE * 2, 0);
-    default:
-      dump("log4moz: unknown appender kind: " + kind);
-      return;
-    }
-  },
-
-  newFormatter: function LogSvc_newFormatter(kind) {
-    switch (kind) {
-    case "basic":
-      return new BasicFormatter();
-    default:
-      dump("log4moz: unknown formatter kind: " + kind);
-      return;
-    }
   }
 };
--- a/services/sync/modules/service.js
+++ b/services/sync/modules/service.js
@@ -222,45 +222,45 @@ WeaveSvc.prototype = {
     }
   },
 
   _initLogs: function WeaveSync__initLogs() {
     this._log = Log4Moz.Service.getLogger("Service.Main");
     this._log.level =
       Log4Moz.Level[Utils.prefs.getCharPref("log.logger.service.main")];
 
-    let formatter = Log4Moz.Service.newFormatter("basic");
+    let formatter = new Log4Moz.BasicFormatter();
     let root = Log4Moz.Service.rootLogger;
     root.level = Log4Moz.Level[Utils.prefs.getCharPref("log.rootLogger")];
 
-    let capp = Log4Moz.Service.newAppender("console", formatter);
+    let capp = new Log4Moz.ConsoleAppender(formatter);
     capp.level = Log4Moz.Level[Utils.prefs.getCharPref("log.appender.console")];
     root.addAppender(capp);
 
-    let dapp = Log4Moz.Service.newAppender("dump", formatter);
+    let dapp = new Log4Moz.DumpAppender(formatter);
     dapp.level = Log4Moz.Level[Utils.prefs.getCharPref("log.appender.dump")];
     root.addAppender(dapp);
 
     let brief = this._dirSvc.get("ProfD", Ci.nsIFile);
     brief.QueryInterface(Ci.nsILocalFile);
     brief.append("weave");
     brief.append("logs");
     brief.append("brief-log.txt");
     if (!brief.exists())
       brief.create(brief.NORMAL_FILE_TYPE, PERMS_FILE);
 
     let verbose = brief.parent.clone();
     verbose.append("verbose-log.txt");
     if (!verbose.exists())
       verbose.create(verbose.NORMAL_FILE_TYPE, PERMS_FILE);
 
-    this._briefApp = Log4Moz.Service.newFileAppender("rotating", brief, formatter);
+    this._briefApp = new Log4Moz.RotatingFileAppender(brief, formatter);
     this._briefApp.level = Log4Moz.Level[Utils.prefs.getCharPref("log.appender.briefLog")];
     root.addAppender(this._briefApp);
-    this._debugApp = Log4Moz.Service.newFileAppender("rotating", verbose, formatter);
+    this._debugApp = new Log4Moz.RotatingFileAppender(verbose, formatter);
     this._debugApp.level = Log4Moz.Level[Utils.prefs.getCharPref("log.appender.debugLog")];
     root.addAppender(this._debugApp);
   },
 
   clearLogs: function WeaveSvc_clearLogs() {
     this._briefApp.clear();
     this._debugApp.clear();
   },
new file mode 100644
--- /dev/null
+++ b/services/sync/tests/unit/test_log4moz.js
@@ -0,0 +1,27 @@
+Components.utils.import("resource://weave/log4moz.js");
+
+function MockAppender(formatter) {
+  this._formatter = formatter;
+  this.messages = [];
+}
+MockAppender.prototype = {
+  doAppend: function DApp_doAppend(message) {
+    this.messages.push(message);
+  }
+};
+MockAppender.prototype.__proto__ = new Log4Moz.Appender();
+
+function run_test() {
+  var log = Log4Moz.Service.rootLogger;
+  var appender = new MockAppender(new Log4Moz.BasicFormatter());
+
+  log.level = Log4Moz.Level.Debug;
+  appender.level = Log4Moz.Level.Info;
+  log.addAppender(appender);
+  log.info("info test");
+  log.debug("this should be logged but not appended.");
+
+  do_check_eq(appender.messages.length, 1);
+  do_check_true(appender.messages[0].indexOf("info test") > 0);
+  do_check_true(appender.messages[0].indexOf("INFO") > 0);
+}