Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 this.EXPORTED_SYMBOLS = [
8 "getTestLogger",
9 "initTestLogging",
10 ];
12 const {utils: Cu} = Components;
14 Cu.import("resource://gre/modules/Log.jsm");
16 this.initTestLogging = function initTestLogging(level) {
17 function LogStats() {
18 this.errorsLogged = 0;
19 }
20 LogStats.prototype = {
21 format: function format(message) {
22 if (message.level == Log.Level.Error) {
23 this.errorsLogged += 1;
24 }
26 return message.loggerName + "\t" + message.levelDesc + "\t" +
27 message.message + "\n";
28 }
29 };
30 LogStats.prototype.__proto__ = new Log.Formatter();
32 let log = Log.repository.rootLogger;
33 let logStats = new LogStats();
34 let appender = new Log.DumpAppender(logStats);
36 if (typeof(level) == "undefined") {
37 level = "Debug";
38 }
39 getTestLogger().level = Log.Level[level];
40 Log.repository.getLogger("Services").level = Log.Level[level];
42 log.level = Log.Level.Trace;
43 appender.level = Log.Level.Trace;
44 // Overwrite any other appenders (e.g. from previous incarnations)
45 log.ownAppenders = [appender];
46 log.updateAppenders();
48 return logStats;
49 }
51 this.getTestLogger = function getTestLogger(component) {
52 return Log.repository.getLogger("Testing");
53 }