Bug 1406475 - Convert logmanager sync module to using Services.prefs. r=sync-reviewers,skhamis
Depends on D180804 Differential Revision: https://phabricator.services.mozilla.com/D180805
This commit is contained in:
@@ -12,8 +12,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
|
||||
NetUtil: "resource://gre/modules/NetUtil.sys.mjs",
|
||||
});
|
||||
|
||||
import { Preferences } from "resource://gre/modules/Preferences.sys.mjs";
|
||||
|
||||
const DEFAULT_MAX_ERROR_AGE = 20 * 24 * 60 * 60; // 20 days
|
||||
|
||||
// "shared" logs (ie, where the same log name is used by multiple LogManager
|
||||
@@ -208,11 +206,8 @@ LogManager.prototype = {
|
||||
_cleaningUpFileLogs: false,
|
||||
|
||||
init(prefRoot, logNames, logFilePrefix) {
|
||||
if (prefRoot instanceof Preferences) {
|
||||
this._prefs = prefRoot;
|
||||
} else {
|
||||
this._prefs = new Preferences(prefRoot);
|
||||
}
|
||||
this._prefs = Services.prefs.getBranch(prefRoot);
|
||||
this._prefsBranch = prefRoot;
|
||||
|
||||
this.logFilePrefix = logFilePrefix;
|
||||
if (!formatter) {
|
||||
@@ -222,7 +217,7 @@ LogManager.prototype = {
|
||||
dumpAppender = new Log.DumpAppender(formatter);
|
||||
}
|
||||
|
||||
allBranches.add(this._prefs._branchStr);
|
||||
allBranches.add(this._prefsBranch);
|
||||
// We create a preference observer for all our prefs so they are magically
|
||||
// reflected if the pref changes after creation.
|
||||
let setupAppender = (
|
||||
@@ -240,8 +235,8 @@ LogManager.prototype = {
|
||||
// For example, if consumerA has dump=Debug then consumerB sets
|
||||
// dump=Error, we need to keep dump=Debug so consumerA is respected.
|
||||
for (let branch of allBranches) {
|
||||
let lookPrefBranch = new Preferences(branch);
|
||||
let lookVal = Log.Level[lookPrefBranch.get(prefName)];
|
||||
let lookPrefBranch = Services.prefs.getBranch(branch);
|
||||
let lookVal = Log.Level[lookPrefBranch.getCharPref(prefName, null)];
|
||||
if (lookVal && lookVal < level) {
|
||||
level = lookVal;
|
||||
}
|
||||
@@ -249,10 +244,10 @@ LogManager.prototype = {
|
||||
}
|
||||
appender.level = level;
|
||||
};
|
||||
this._prefs.observe(prefName, observer, this);
|
||||
this._prefs.addObserver(prefName, observer);
|
||||
this._prefObservers.push([prefName, observer]);
|
||||
// and call the observer now with the current pref value.
|
||||
observer(this._prefs.get(prefName));
|
||||
observer(this._prefs.getCharPref(prefName, null));
|
||||
return observer;
|
||||
};
|
||||
|
||||
@@ -294,12 +289,12 @@ LogManager.prototype = {
|
||||
* Cleanup this instance
|
||||
*/
|
||||
finalize() {
|
||||
for (let [name, pref] of this._prefObservers) {
|
||||
this._prefs.ignore(name, pref, this);
|
||||
for (let [prefName, observer] of this._prefObservers) {
|
||||
this._prefs.removeObserver(prefName, observer);
|
||||
}
|
||||
this._prefObservers = [];
|
||||
try {
|
||||
allBranches.delete(this._prefs._branchStr);
|
||||
allBranches.delete(this._prefsBranch);
|
||||
} catch (e) {}
|
||||
this._prefs = null;
|
||||
},
|
||||
@@ -336,11 +331,17 @@ LogManager.prototype = {
|
||||
let reason;
|
||||
if (this._fileAppender.sawError) {
|
||||
reason = this.ERROR_LOG_WRITTEN;
|
||||
flushToFile = this._prefs.get("log.appender.file.logOnError", true);
|
||||
flushToFile = this._prefs.getBoolPref(
|
||||
"log.appender.file.logOnError",
|
||||
true
|
||||
);
|
||||
reasonPrefix = "error";
|
||||
} else {
|
||||
reason = this.SUCCESS_LOG_WRITTEN;
|
||||
flushToFile = this._prefs.get("log.appender.file.logOnSuccess", false);
|
||||
flushToFile = this._prefs.getBoolPref(
|
||||
"log.appender.file.logOnSuccess",
|
||||
false
|
||||
);
|
||||
reasonPrefix = "success";
|
||||
}
|
||||
|
||||
@@ -383,7 +384,7 @@ LogManager.prototype = {
|
||||
* Finds all logs older than maxErrorAge and deletes them using async I/O.
|
||||
*/
|
||||
cleanupLogs() {
|
||||
let maxAge = this._prefs.get(
|
||||
let maxAge = this._prefs.getIntPref(
|
||||
"log.appender.file.maxErrorAge",
|
||||
DEFAULT_MAX_ERROR_AGE
|
||||
);
|
||||
|
||||
@@ -5,9 +5,6 @@
|
||||
const { XPCOMUtils } = ChromeUtils.importESModule(
|
||||
"resource://gre/modules/XPCOMUtils.sys.mjs"
|
||||
);
|
||||
const { Preferences } = ChromeUtils.importESModule(
|
||||
"resource://gre/modules/Preferences.sys.mjs"
|
||||
);
|
||||
const { Log } = ChromeUtils.importESModule(
|
||||
"resource://gre/modules/Log.sys.mjs"
|
||||
);
|
||||
@@ -45,7 +42,7 @@ XPCOMUtils.defineLazyGetter(exports, "logManager", function () {
|
||||
];
|
||||
|
||||
// for legacy reasons, the log manager still thinks it's part of sync
|
||||
return new LogManager(new Preferences("services.sync."), logs, "sync");
|
||||
return new LogManager("services.sync.", logs, "sync");
|
||||
});
|
||||
|
||||
// A boolean to indicate if personally identifiable information (or anything
|
||||
|
||||
Reference in New Issue
Block a user