зеркало из https://github.com/mozilla/pjs.git
Merged changes
This commit is contained in:
Коммит
25d2cb8e20
|
@ -84,7 +84,15 @@ let Log4Moz = {
|
|||
delete Log4Moz.Service;
|
||||
Log4Moz.Service = new Log4MozService();
|
||||
return Log4Moz.Service;
|
||||
}
|
||||
},
|
||||
|
||||
get Formatter() { return Formatter; },
|
||||
get BasicFormatter() { return BasicFormatter; },
|
||||
get Appender() { return Appender; },
|
||||
get DumpAppender() { return DumpAppender; },
|
||||
get ConsoleAppender() { return ConsoleAppender; },
|
||||
get FileAppender() { return FileAppender; },
|
||||
get RotatingFileAppender() { return RotatingFileAppender; }
|
||||
};
|
||||
|
||||
|
||||
|
@ -412,6 +420,12 @@ FileAppender.prototype.__proto__ = new Appender();
|
|||
*/
|
||||
|
||||
function RotatingFileAppender(file, formatter, maxSize, maxBackups) {
|
||||
if (maxSize === undefined)
|
||||
maxSize = ONE_MEGABYTE * 2;
|
||||
|
||||
if (maxBackups === undefined)
|
||||
maxBackups = 0;
|
||||
|
||||
this._name = "RotatingFileAppender";
|
||||
this._file = file; // nsIFile
|
||||
this._formatter = formatter;
|
||||
|
@ -471,40 +485,5 @@ Log4MozService.prototype = {
|
|||
|
||||
getLogger: function LogSvc_getLogger(name) {
|
||||
return this._repository.getLogger(name);
|
||||
},
|
||||
|
||||
newAppender: function LogSvc_newAppender(kind, formatter) {
|
||||
switch (kind) {
|
||||
case "dump":
|
||||
return new DumpAppender(formatter);
|
||||
case "console":
|
||||
return new ConsoleAppender(formatter);
|
||||
default:
|
||||
dump("log4moz: unknown appender kind: " + kind);
|
||||
return;
|
||||
}
|
||||
},
|
||||
|
||||
newFileAppender: function LogSvc_newAppender(kind, file, formatter) {
|
||||
switch (kind) {
|
||||
case "file":
|
||||
return new FileAppender(file, formatter);
|
||||
case "rotating":
|
||||
// FIXME: hardcoded constants
|
||||
return new RotatingFileAppender(file, formatter, ONE_MEGABYTE * 2, 0);
|
||||
default:
|
||||
dump("log4moz: unknown appender kind: " + kind);
|
||||
return;
|
||||
}
|
||||
},
|
||||
|
||||
newFormatter: function LogSvc_newFormatter(kind) {
|
||||
switch (kind) {
|
||||
case "basic":
|
||||
return new BasicFormatter();
|
||||
default:
|
||||
dump("log4moz: unknown formatter kind: " + kind);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -227,15 +227,15 @@ WeaveSvc.prototype = {
|
|||
this._log.level =
|
||||
Log4Moz.Level[Utils.prefs.getCharPref("log.logger.service.main")];
|
||||
|
||||
let formatter = Log4Moz.Service.newFormatter("basic");
|
||||
let formatter = new Log4Moz.BasicFormatter();
|
||||
let root = Log4Moz.Service.rootLogger;
|
||||
root.level = Log4Moz.Level[Utils.prefs.getCharPref("log.rootLogger")];
|
||||
|
||||
let capp = Log4Moz.Service.newAppender("console", formatter);
|
||||
let capp = new Log4Moz.ConsoleAppender(formatter);
|
||||
capp.level = Log4Moz.Level[Utils.prefs.getCharPref("log.appender.console")];
|
||||
root.addAppender(capp);
|
||||
|
||||
let dapp = Log4Moz.Service.newAppender("dump", formatter);
|
||||
let dapp = new Log4Moz.DumpAppender(formatter);
|
||||
dapp.level = Log4Moz.Level[Utils.prefs.getCharPref("log.appender.dump")];
|
||||
root.addAppender(dapp);
|
||||
|
||||
|
@ -252,10 +252,10 @@ WeaveSvc.prototype = {
|
|||
if (!verbose.exists())
|
||||
verbose.create(verbose.NORMAL_FILE_TYPE, PERMS_FILE);
|
||||
|
||||
this._briefApp = Log4Moz.Service.newFileAppender("rotating", brief, formatter);
|
||||
this._briefApp = new Log4Moz.RotatingFileAppender(brief, formatter);
|
||||
this._briefApp.level = Log4Moz.Level[Utils.prefs.getCharPref("log.appender.briefLog")];
|
||||
root.addAppender(this._briefApp);
|
||||
this._debugApp = Log4Moz.Service.newFileAppender("rotating", verbose, formatter);
|
||||
this._debugApp = new Log4Moz.RotatingFileAppender(verbose, formatter);
|
||||
this._debugApp.level = Log4Moz.Level[Utils.prefs.getCharPref("log.appender.debugLog")];
|
||||
root.addAppender(this._debugApp);
|
||||
},
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
Components.utils.import("resource://weave/log4moz.js");
|
||||
|
||||
function MockAppender(formatter) {
|
||||
this._formatter = formatter;
|
||||
this.messages = [];
|
||||
}
|
||||
MockAppender.prototype = {
|
||||
doAppend: function DApp_doAppend(message) {
|
||||
this.messages.push(message);
|
||||
}
|
||||
};
|
||||
MockAppender.prototype.__proto__ = new Log4Moz.Appender();
|
||||
|
||||
function run_test() {
|
||||
var log = Log4Moz.Service.rootLogger;
|
||||
var appender = new MockAppender(new Log4Moz.BasicFormatter());
|
||||
|
||||
log.level = Log4Moz.Level.Debug;
|
||||
appender.level = Log4Moz.Level.Info;
|
||||
log.addAppender(appender);
|
||||
log.info("info test");
|
||||
log.debug("this should be logged but not appended.");
|
||||
|
||||
do_check_eq(appender.messages.length, 1);
|
||||
do_check_true(appender.messages[0].indexOf("info test") > 0);
|
||||
do_check_true(appender.messages[0].indexOf("INFO") > 0);
|
||||
}
|
Загрузка…
Ссылка в новой задаче