/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/** * Resets all the preferences in the logging. branch * This is needed because we may crash while logging, and this would cause us * to log after restarting as well. * * If logging after restart is desired, set the logging.config.clear_on_startup * pref to false, or use the MOZ_LOG_FILE and MOZ_LOG_MODULES env vars.
*/ staticvoid ResetExistingPrefs() {
nsTArray<nsCString> names;
nsresult rv =
Preferences::GetRootBranch()->GetChildList(kLoggingPrefPrefix, names); if (NS_SUCCEEDED(rv)) { for (auto& name : names) { // Clearing the pref will cause it to reload, thus resetting the log level
Preferences::ClearUser(name.get());
}
}
}
/** * Loads the log level from the given pref and updates the corresponding * LogModule.
*/ staticvoid LoadPrefValue(constchar* aName) {
LogLevel logLevel = LogLevel::Disabled;
if (strncmp(aName, kLoggingConfigPrefPrefix, kLoggingConfigPrefixLen) == 0) {
nsAutoCString prefName(aName);
if (prefName.EqualsLiteral(kLoggingPrefLogFile)) {
rv = Preferences::GetCString(aName, prefValue); // The pref was reset. Clear the user file. if (NS_FAILED(rv) || prefValue.IsEmpty()) {
LogModule::SetLogFile(nullptr); return;
}
// If the pref value doesn't have a PID placeholder, append it to the end. if (!strstr(prefValue.get(), MOZ_LOG_PID_TOKEN)) {
prefValue.AppendLiteral(MOZ_LOG_PID_TOKEN);
}
LogModule::SetLogFile(prefValue.BeginReading());
} elseif (prefName.EqualsLiteral(kLoggingPrefAddTimestamp)) { bool addTimestamp = Preferences::GetBool(aName, false);
LogModule::SetAddTimestamp(addTimestamp);
} elseif (prefName.EqualsLiteral(kLoggingPrefSync)) { bool sync = Preferences::GetBool(aName, false);
LogModule::SetIsSync(sync);
} elseif (prefName.EqualsLiteral(kLoggingPrefStacks)) { bool captureStacks = Preferences::GetBool(aName, false);
LogModule::SetCaptureStacks(captureStacks);
} elseif (prefName.EqualsLiteral(kLoggingPrefLogModules)) { // The content of the preference will be parsed as a MOZ_LOG string, then // the corresponding log modules (if any) will be enabled, others will be // disabled.
LogModule::DisableModules();
LogModule::SetCaptureStacks(false);
if (hasModulesEnv || hasModulesPref) {
NSPRLogModulesParser(
hasModulesPref ? prefValue.BeginReading() : modulesFromEnv,
[](constchar* aName, LogLevel aLevel, int32_t aValue) mutable { // Only the special string "profilerstacks" is taken into account, // because we're especially interested in usage with the Firefox // Profiler. if (strcmp(aName, "profilerstacks") == 0) {
LogModule::SetCaptureStacks(true);
} else {
LogModule::Get(aName)->SetLevel(aLevel);
}
});
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.