michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: this.EXPORTED_SYMBOLS = [ michael@0: "getTestLogger", michael@0: "initTestLogging", michael@0: ]; michael@0: michael@0: const {utils: Cu} = Components; michael@0: michael@0: Cu.import("resource://gre/modules/Log.jsm"); michael@0: michael@0: this.initTestLogging = function initTestLogging(level) { michael@0: function LogStats() { michael@0: this.errorsLogged = 0; michael@0: } michael@0: LogStats.prototype = { michael@0: format: function format(message) { michael@0: if (message.level == Log.Level.Error) { michael@0: this.errorsLogged += 1; michael@0: } michael@0: michael@0: return message.loggerName + "\t" + message.levelDesc + "\t" + michael@0: message.message + "\n"; michael@0: } michael@0: }; michael@0: LogStats.prototype.__proto__ = new Log.Formatter(); michael@0: michael@0: let log = Log.repository.rootLogger; michael@0: let logStats = new LogStats(); michael@0: let appender = new Log.DumpAppender(logStats); michael@0: michael@0: if (typeof(level) == "undefined") { michael@0: level = "Debug"; michael@0: } michael@0: getTestLogger().level = Log.Level[level]; michael@0: Log.repository.getLogger("Services").level = Log.Level[level]; michael@0: michael@0: log.level = Log.Level.Trace; michael@0: appender.level = Log.Level.Trace; michael@0: // Overwrite any other appenders (e.g. from previous incarnations) michael@0: log.ownAppenders = [appender]; michael@0: log.updateAppenders(); michael@0: michael@0: return logStats; michael@0: } michael@0: michael@0: this.getTestLogger = function getTestLogger(component) { michael@0: return Log.repository.getLogger("Testing"); michael@0: } michael@0: