diff --git a/mailnews/db/gloda/modules/collection.js b/mailnews/db/gloda/modules/collection.js index bad75dfbef..420e17bcf8 100644 --- a/mailnews/db/gloda/modules/collection.js +++ b/mailnews/db/gloda/modules/collection.js @@ -44,7 +44,7 @@ const Cu = Components.utils; Cu.import("resource://app/modules/gloda/log4moz.js"); -const LOG = Log4Moz.Service.getLogger("gloda.collection"); +const LOG = Log4Moz.repository.getLogger("gloda.collection"); /** * @namespace Central registry and logic for all collections. diff --git a/mailnews/db/gloda/modules/connotent.js b/mailnews/db/gloda/modules/connotent.js index d50d8b5cfa..0e3ae76b97 100644 --- a/mailnews/db/gloda/modules/connotent.js +++ b/mailnews/db/gloda/modules/connotent.js @@ -44,7 +44,7 @@ const Cu = Components.utils; Cu.import("resource://app/modules/gloda/log4moz.js"); -const LOG = Log4Moz.Service.getLogger("gloda.connotent"); +const LOG = Log4Moz.repository.getLogger("gloda.connotent"); function GlodaContent() { this._contentPriority = null; @@ -226,4 +226,4 @@ GlodaContent.prototype = { else this._curHunk.data += "\n" + data; }, -} \ No newline at end of file +} diff --git a/mailnews/db/gloda/modules/databind.js b/mailnews/db/gloda/modules/databind.js index 911e0791f2..4d580e4f2c 100644 --- a/mailnews/db/gloda/modules/databind.js +++ b/mailnews/db/gloda/modules/databind.js @@ -44,7 +44,7 @@ const Cu = Components.utils; Cu.import("resource://app/modules/gloda/log4moz.js"); -let DBC_LOG = Log4Moz.Service.getLogger("gloda.ds.dbc"); +let DBC_LOG = Log4Moz.repository.getLogger("gloda.ds.dbc"); function DatabindCallback(aDatabind, aCallbackThis, aCallback, aOneShot) { this._databind = aDatabind; @@ -92,7 +92,7 @@ DatabindCallback.prototype = { function GlodaDatabind(aTableDef, aDatastore) { this._tableDef = aTableDef; this._datastore = aDatastore; - this._log = Log4Moz.Service.getLogger("gloda.databind." + aTableDef.name); + this._log = Log4Moz.repository.getLogger("gloda.databind." + aTableDef.name); let insertSql = "INSERT INTO " + this._tableDef._realName + " (" + [coldef[0] for each diff --git a/mailnews/db/gloda/modules/datamodel.js b/mailnews/db/gloda/modules/datamodel.js index d58754ae7a..fb138efe85 100644 --- a/mailnews/db/gloda/modules/datamodel.js +++ b/mailnews/db/gloda/modules/datamodel.js @@ -45,7 +45,7 @@ const Cr = Components.results; const Cu = Components.utils; Cu.import("resource://app/modules/gloda/log4moz.js"); -const LOG = Log4Moz.Service.getLogger("gloda.datamodel"); +const LOG = Log4Moz.repository.getLogger("gloda.datamodel"); Cu.import("resource://app/modules/gloda/utils.js"); diff --git a/mailnews/db/gloda/modules/datastore.js b/mailnews/db/gloda/modules/datastore.js index b68c3f8f31..df5e9b879c 100644 --- a/mailnews/db/gloda/modules/datastore.js +++ b/mailnews/db/gloda/modules/datastore.js @@ -53,7 +53,7 @@ Cu.import("resource://app/modules/gloda/datamodel.js"); Cu.import("resource://app/modules/gloda/databind.js"); Cu.import("resource://app/modules/gloda/collection.js"); -let MBM_LOG = Log4Moz.Service.getLogger("gloda.ds.mbm"); +let MBM_LOG = Log4Moz.repository.getLogger("gloda.ds.mbm"); /** * @class This callback handles processing the asynchronous query results of @@ -99,7 +99,7 @@ MessagesByMessageIdCallback.prototype = { } }; -let PCH_LOG = Log4Moz.Service.getLogger("gloda.ds.pch"); +let PCH_LOG = Log4Moz.repository.getLogger("gloda.ds.pch"); function PostCommitHandler(aCallbacks) { this.callbacks = aCallbacks; @@ -140,7 +140,7 @@ PostCommitHandler.prototype = { } }; -let QFQ_LOG = Log4Moz.Service.getLogger("gloda.ds.qfq"); +let QFQ_LOG = Log4Moz.repository.getLogger("gloda.ds.qfq"); let QueryFromQueryResolver = { onItemsAdded: function(aIgnoredItems, aCollection, aFake) { @@ -742,7 +742,7 @@ var GlodaDatastore = { * mapping. */ _init: function gloda_ds_init(aNsJSON, aNounIDToDef) { - this._log = Log4Moz.Service.getLogger("gloda.datastore"); + this._log = Log4Moz.repository.getLogger("gloda.datastore"); this._log.debug("Beginning datastore initialization."); this._json = aNsJSON; diff --git a/mailnews/db/gloda/modules/everybody.js b/mailnews/db/gloda/modules/everybody.js index 233d0a0027..d3307f8f5c 100644 --- a/mailnews/db/gloda/modules/everybody.js +++ b/mailnews/db/gloda/modules/everybody.js @@ -43,7 +43,7 @@ const Cr = Components.results; const Cu = Components.utils; Cu.import("resource://app/modules/gloda/log4moz.js"); -const LOG = Log4Moz.Service.getLogger("gloda.everybody"); +const LOG = Log4Moz.repository.getLogger("gloda.everybody"); var importNS = {}; diff --git a/mailnews/db/gloda/modules/explattr.js b/mailnews/db/gloda/modules/explattr.js index 9ffe409408..9b4a3a3cde 100644 --- a/mailnews/db/gloda/modules/explattr.js +++ b/mailnews/db/gloda/modules/explattr.js @@ -72,7 +72,7 @@ var GlodaExplicitAttr = { _msgTagService: null, init: function gloda_explattr_init() { - this._log = Log4Moz.Service.getLogger("gloda.explattr"); + this._log = Log4Moz.repository.getLogger("gloda.explattr"); this._msgTagService = Cc["@mozilla.org/messenger/tagservice;1"]. getService(Ci.nsIMsgTagService); diff --git a/mailnews/db/gloda/modules/fundattr.js b/mailnews/db/gloda/modules/fundattr.js index 878d24693c..e866f79ea7 100644 --- a/mailnews/db/gloda/modules/fundattr.js +++ b/mailnews/db/gloda/modules/fundattr.js @@ -63,7 +63,7 @@ var GlodaFundAttr = { _log: null, init: function gloda_explattr_init() { - this._log = Log4Moz.Service.getLogger("gloda.fundattr"); + this._log = Log4Moz.repository.getLogger("gloda.fundattr"); try { this.defineAttributes(); diff --git a/mailnews/db/gloda/modules/gloda.js b/mailnews/db/gloda/modules/gloda.js index 1aa3268679..febe4ad6f9 100644 --- a/mailnews/db/gloda/modules/gloda.js +++ b/mailnews/db/gloda/modules/gloda.js @@ -165,7 +165,7 @@ var Gloda = { */ _initLogging: function gloda_ns_initLogging() { let formatter = new Log4Moz.BasicFormatter(); - let root = Log4Moz.Service.rootLogger; + let root = Log4Moz.repository.rootLogger; root.level = Log4Moz.Level.Debug; let enableConsoleLogging = false; @@ -210,7 +210,7 @@ var Gloda = { } } - this._log = Log4Moz.Service.getLogger("gloda.NS"); + this._log = Log4Moz.repository.getLogger("gloda.NS"); this._log.info("Logging Initialized"); }, diff --git a/mailnews/db/gloda/modules/index_ab.js b/mailnews/db/gloda/modules/index_ab.js index 2cb16ff88a..769027c025 100644 --- a/mailnews/db/gloda/modules/index_ab.js +++ b/mailnews/db/gloda/modules/index_ab.js @@ -60,7 +60,7 @@ var GlodaABIndexer = { name: "ab_indexer", enable: function() { if (this._log == null) - this._log = Log4Moz.Service.getLogger("gloda.ab_indexer"); + this._log = Log4Moz.repository.getLogger("gloda.ab_indexer"); let abManager = Cc["@mozilla.org/abmanager;1"].getService(Ci.nsIAbManager); abManager.addAddressBookListener(this, Ci.nsIAbListener.itemChanged); @@ -125,7 +125,7 @@ var GlodaABAttrs = { _log: null, init: function() { - this._log = Log4Moz.Service.getLogger("gloda.abattrs"); + this._log = Log4Moz.repository.getLogger("gloda.abattrs"); try { this.defineAttributes(); diff --git a/mailnews/db/gloda/modules/indexer.js b/mailnews/db/gloda/modules/indexer.js index d69e66d3d8..1cab9d16bb 100644 --- a/mailnews/db/gloda/modules/indexer.js +++ b/mailnews/db/gloda/modules/indexer.js @@ -69,7 +69,7 @@ function range(begin, end) { } } -const GFI = Log4Moz.Service.getLogger("gloda.fixiterator"); +const GFI = Log4Moz.repository.getLogger("gloda.fixiterator"); // FROM STEEL (a la Joey Minta/jminta) @@ -281,7 +281,7 @@ var GlodaIndexer = { * GlodaDatastore. */ _datastore: GlodaDatastore, - _log: Log4Moz.Service.getLogger("gloda.indexer"), + _log: Log4Moz.repository.getLogger("gloda.indexer"), /** * Our nsITimer that we use to schedule ourselves on the main thread * intermittently. The timer always exists but may not always be active. diff --git a/mailnews/db/gloda/modules/log4moz.js b/mailnews/db/gloda/modules/log4moz.js index 3173403e75..a8dc9f01f3 100644 --- a/mailnews/db/gloda/modules/log4moz.js +++ b/mailnews/db/gloda/modules/log4moz.js @@ -87,11 +87,19 @@ let Log4Moz = { } }, - get Service() { - delete Log4Moz.Service; - Log4Moz.Service = new Log4MozService(); - return Log4Moz.Service; + get repository() { + delete Log4Moz.repository; + Log4Moz.repository = new LoggerRepository(); + return Log4Moz.repository; }, + set repository(value) { + delete Log4Moz.repository; + Log4Moz.repository = value; + }, + + get LogMessage() { return LogMessage; }, + get Logger() { return Logger; }, + get LoggerRepository() { return LoggerRepository; }, get Formatter() { return Formatter; }, get BasicFormatter() { return BasicFormatter; }, @@ -105,9 +113,9 @@ let Log4Moz = { get ThrowingAppender() { return ThrowingAppender; }, // Logging helper: - // let logger = Log4Moz.Service.getLogger("foo"); + // let logger = Log4Moz.repository.getLogger("foo"); // logger.info(Log4Moz.enumerateInterfaces(someObject).join(",")); - enumerateInterfaces: function(aObject) { + enumerateInterfaces: function Log4Moz_enumerateInterfaces(aObject) { let interfaces = []; for (i in Ci) { @@ -122,9 +130,10 @@ let Log4Moz = { }, // Logging helper: - // let logger = Log4Moz.Service.getLogger("foo"); + // let logger = Log4Moz.repository.getLogger("foo"); // logger.info(Log4Moz.enumerateProperties(someObject).join(",")); - enumerateProperties: function(aObject, aExcludeComplexTypes) { + enumerateProperties: function Log4Moz_enumerateProps(aObject, + aExcludeComplexTypes) { let properties = []; for (p in aObject) { @@ -175,15 +184,25 @@ LogMessage.prototype = { */ function Logger(name, repository) { - this._name = name; - this._repository = repository; - this._appenders = []; + this._init(name, repository); } Logger.prototype = { + _init: function Logger__init(name, repository) { + if (!repository) + repository = Log4Moz.repository; + this._name = name; + this._appenders = []; + this._repository = repository; + }, + QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]), parent: null, + get name() { + return this._name; + }, + _level: null, get level() { if (this._level != null) @@ -273,7 +292,9 @@ LoggerRepository.prototype = { let cur, parent; // find the closest parent - for (let i = 0; i < pieces.length; i++) { + // don't test for the logger name itself, as there's a chance it's already + // there in this._loggers + for (let i = 0; i < pieces.length - 1; i++) { if (cur) cur += '.' + pieces[i]; else @@ -282,24 +303,26 @@ LoggerRepository.prototype = { parent = cur; } - // if they are the same it has no parent - if (parent == name) + // if we didn't assign a parent above, there is no parent + if (!parent) this._loggers[name].parent = this.rootLogger; else this._loggers[name].parent = this._loggers[parent]; // trigger updates for any possible descendants of this logger for (let logger in this._loggers) { - if (logger != name && name.indexOf(logger) == 0) + if (logger != name && logger.indexOf(name) == 0) this._updateParents(logger); } }, getLogger: function LogRep_getLogger(name) { - if (!(name in this._loggers)) { - this._loggers[name] = new Logger(name, this); - this._updateParents(name); - } + if (!name) + name = this.getLogger.caller.name; + if (name in this._loggers) + return this._loggers[name]; + this._loggers[name] = new Logger(name, this); + this._updateParents(name); return this._loggers[name]; } }; @@ -323,6 +346,8 @@ function BasicFormatter(dateFormat) { this.dateFormat = dateFormat; } BasicFormatter.prototype = { + __proto__: Formatter.prototype, + _dateFormat: null, get dateFormat() { @@ -342,7 +367,6 @@ BasicFormatter.prototype = { message.message + "\n"; } }; -BasicFormatter.prototype.__proto__ = new Formatter(); /* * XMLFormatter @@ -355,6 +379,8 @@ BasicFormatter.prototype.__proto__ = new Formatter(); function XMLFormatter() {} XMLFormatter.prototype = { + __proto__: Formatter.prototype, + format: function XF_format(message) { let cdataEscapedMessage = message.message.replace(CDATA_END, CDATA_ESCAPED_END, "g"); @@ -365,7 +391,6 @@ XMLFormatter.prototype = { ""; } } -XMLFormatter.prototype.__proto__ = new Formatter(); /* * Appenders @@ -402,14 +427,15 @@ Appender.prototype = { function DumpAppender(formatter) { this._name = "DumpAppender"; - this._formatter = formatter; + this._formatter = formatter? formatter : new BasicFormatter(); } DumpAppender.prototype = { + __proto__: Appender.prototype, + doAppend: function DApp_doAppend(message) { dump(message); } }; -DumpAppender.prototype.__proto__ = new Appender(); /* * ConsoleAppender @@ -421,6 +447,8 @@ function ConsoleAppender(formatter) { this._formatter = formatter; } ConsoleAppender.prototype = { + __proto__: Appender.prototype, + doAppend: function CApp_doAppend(message) { if (message.level > Log4Moz.Level.Warn) { Cu.reportError(message); @@ -430,7 +458,6 @@ ConsoleAppender.prototype = { getService(Ci.nsIConsoleService).logStringMessage(message); } }; -ConsoleAppender.prototype.__proto__ = new Appender(); /* * FileAppender @@ -440,9 +467,11 @@ ConsoleAppender.prototype.__proto__ = new Appender(); function FileAppender(file, formatter) { this._name = "FileAppender"; this._file = file; // nsIFile - this._formatter = formatter; + this._formatter = formatter? formatter : new BasicFormatter(); } FileAppender.prototype = { + __proto__: Appender.prototype, + __fos: null, get _fos() { if (!this.__fos) @@ -483,7 +512,6 @@ FileAppender.prototype = { this._file.remove(false); } }; -FileAppender.prototype.__proto__ = new Appender(); /* * RotatingFileAppender @@ -499,11 +527,13 @@ function RotatingFileAppender(file, formatter, maxSize, maxBackups) { this._name = "RotatingFileAppender"; this._file = file; // nsIFile - this._formatter = formatter; + this._formatter = formatter? formatter : new BasicFormatter(); this._maxSize = maxSize; this._maxBackups = maxBackups; } RotatingFileAppender.prototype = { + __proto__: FileAppender.prototype, + doAppend: function RFApp_doAppend(message) { if (message === null || message.length <= 0) return; @@ -535,7 +565,6 @@ RotatingFileAppender.prototype = { // Note: this._file still points to the same file } }; -RotatingFileAppender.prototype.__proto__ = new FileAppender(); /* * SocketAppender @@ -558,6 +587,8 @@ function SocketAppender(host, port, formatter, timeoutDelay) { Cc["@mozilla.org/thread-manager;1"].getService().mainThread; } SocketAppender.prototype = { + __proto__: Appender.prototype, + __nos: null, get _nos() { if (!this.__nos) @@ -634,10 +665,7 @@ SocketAppender.prototype = { if (aStatus == 0x804b0004) // STATUS_CONNECTED_TO is not a constant. this._connected = true; }, - }; -SocketAppender.prototype.__proto__ = new Appender(); - /** * Throws an exception whenever it gets a message. Intended to be used in @@ -650,6 +678,8 @@ function ThrowingAppender(thrower) { this._thrower = thrower; } ThrowingAppender.prototype = { + __proto__: Appender.prototype, + doAppend: function TApp_doAppend(message) { if (this._thrower) this._thrower(message); @@ -657,27 +687,3 @@ ThrowingAppender.prototype = { throw message; } }; -ThrowingAppender.prototype.__proto__ = new Appender(); - - -/* - * LoggingService - */ - -function Log4MozService() { - this._repository = new LoggerRepository(); -} -Log4MozService.prototype = { - //classDescription: "Log4moz Logging Service", - //contractID: "@mozilla.org/log4moz/service;1", - //classID: Components.ID("{a60e50d7-90b8-4a12-ad0c-79e6a1896978}"), - QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]), - - get rootLogger() { - return this._repository.rootLogger; - }, - - getLogger: function LogSvc_getLogger(name) { - return this._repository.getLogger(name); - } -}; diff --git a/mailnews/db/gloda/modules/noun_freetag.js b/mailnews/db/gloda/modules/noun_freetag.js index 0698555877..e586783b64 100644 --- a/mailnews/db/gloda/modules/noun_freetag.js +++ b/mailnews/db/gloda/modules/noun_freetag.js @@ -61,7 +61,7 @@ FreeTag.prototype = { * parameter, we are an odd case and semantically confused. */ var FreeTagNoun = { - _log: Log4Moz.Service.getLogger("gloda.noun.freetag"), + _log: Log4Moz.repository.getLogger("gloda.noun.freetag"), name: "freetag", class: FreeTag, diff --git a/mailnews/db/gloda/modules/noun_mimetype.js b/mailnews/db/gloda/modules/noun_mimetype.js index 12553a34e4..f67d5c8d16 100644 --- a/mailnews/db/gloda/modules/noun_mimetype.js +++ b/mailnews/db/gloda/modules/noun_mimetype.js @@ -44,7 +44,7 @@ const Cu = Components.utils; Cu.import("resource://app/modules/gloda/log4moz.js"); -const LOG = Log4Moz.Service.getLogger("gloda.noun.mimetype"); +const LOG = Log4Moz.repository.getLogger("gloda.noun.mimetype"); Cu.import("resource://app/modules/gloda/gloda.js"); diff --git a/mailnews/db/gloda/test/resources/glodaTestHelper.js b/mailnews/db/gloda/test/resources/glodaTestHelper.js index e97e14f571..3212d0b253 100644 --- a/mailnews/db/gloda/test/resources/glodaTestHelper.js +++ b/mailnews/db/gloda/test/resources/glodaTestHelper.js @@ -57,7 +57,7 @@ Components.utils.import("resource://app/modules/gloda/indexer.js"); Components.utils.import("resource://app/modules/gloda/log4moz.js"); let throwingAppender = new Log4Moz.ThrowingAppender(do_throw); throwingAppender.level = Log4Moz.Level.Warn; -Log4Moz.Service.rootLogger.addAppender(throwingAppender); +Log4Moz.repository.rootLogger.addAppender(throwingAppender); /** * davida's patented dump function for what ails you.