1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/services/common/modules-testing/logging.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,54 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +this.EXPORTED_SYMBOLS = [ 1.11 + "getTestLogger", 1.12 + "initTestLogging", 1.13 +]; 1.14 + 1.15 +const {utils: Cu} = Components; 1.16 + 1.17 +Cu.import("resource://gre/modules/Log.jsm"); 1.18 + 1.19 +this.initTestLogging = function initTestLogging(level) { 1.20 + function LogStats() { 1.21 + this.errorsLogged = 0; 1.22 + } 1.23 + LogStats.prototype = { 1.24 + format: function format(message) { 1.25 + if (message.level == Log.Level.Error) { 1.26 + this.errorsLogged += 1; 1.27 + } 1.28 + 1.29 + return message.loggerName + "\t" + message.levelDesc + "\t" + 1.30 + message.message + "\n"; 1.31 + } 1.32 + }; 1.33 + LogStats.prototype.__proto__ = new Log.Formatter(); 1.34 + 1.35 + let log = Log.repository.rootLogger; 1.36 + let logStats = new LogStats(); 1.37 + let appender = new Log.DumpAppender(logStats); 1.38 + 1.39 + if (typeof(level) == "undefined") { 1.40 + level = "Debug"; 1.41 + } 1.42 + getTestLogger().level = Log.Level[level]; 1.43 + Log.repository.getLogger("Services").level = Log.Level[level]; 1.44 + 1.45 + log.level = Log.Level.Trace; 1.46 + appender.level = Log.Level.Trace; 1.47 + // Overwrite any other appenders (e.g. from previous incarnations) 1.48 + log.ownAppenders = [appender]; 1.49 + log.updateAppenders(); 1.50 + 1.51 + return logStats; 1.52 +} 1.53 + 1.54 +this.getTestLogger = function getTestLogger(component) { 1.55 + return Log.repository.getLogger("Testing"); 1.56 +} 1.57 +