|
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/. */ |
|
4 |
|
5 "use strict"; |
|
6 |
|
7 this.EXPORTED_SYMBOLS = [ |
|
8 "getTestLogger", |
|
9 "initTestLogging", |
|
10 ]; |
|
11 |
|
12 const {utils: Cu} = Components; |
|
13 |
|
14 Cu.import("resource://gre/modules/Log.jsm"); |
|
15 |
|
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 } |
|
25 |
|
26 return message.loggerName + "\t" + message.levelDesc + "\t" + |
|
27 message.message + "\n"; |
|
28 } |
|
29 }; |
|
30 LogStats.prototype.__proto__ = new Log.Formatter(); |
|
31 |
|
32 let log = Log.repository.rootLogger; |
|
33 let logStats = new LogStats(); |
|
34 let appender = new Log.DumpAppender(logStats); |
|
35 |
|
36 if (typeof(level) == "undefined") { |
|
37 level = "Debug"; |
|
38 } |
|
39 getTestLogger().level = Log.Level[level]; |
|
40 Log.repository.getLogger("Services").level = Log.Level[level]; |
|
41 |
|
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(); |
|
47 |
|
48 return logStats; |
|
49 } |
|
50 |
|
51 this.getTestLogger = function getTestLogger(component) { |
|
52 return Log.repository.getLogger("Testing"); |
|
53 } |
|
54 |