services/common/modules-testing/logging.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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 }

mercurial