mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-02-27 01:17:43 +01:00
chrome: Support CefSettings logging config (see #3685)
Also enables logging by default for Release builds (previously required the `--enable-logging` flag). Logging can still be disabled by passing the `--disable-logging` flag.
This commit is contained in:
parent
6b13b1c627
commit
4e3668f93a
@ -125,6 +125,8 @@ void ChromeContentBrowserClientCef::AppendExtraCommandLineSwitches(
|
|||||||
switches::kMainBundlePath,
|
switches::kMainBundlePath,
|
||||||
#endif
|
#endif
|
||||||
switches::kLocalesDirPath,
|
switches::kLocalesDirPath,
|
||||||
|
switches::kLogItems,
|
||||||
|
switches::kLogSeverity,
|
||||||
switches::kResourcesDirPath,
|
switches::kResourcesDirPath,
|
||||||
switches::kUserAgentProductAndVersion,
|
switches::kUserAgentProductAndVersion,
|
||||||
};
|
};
|
||||||
|
@ -42,6 +42,76 @@ namespace {
|
|||||||
base::LazyInstance<ChromeContentRendererClientCef>::DestructorAtExit
|
base::LazyInstance<ChromeContentRendererClientCef>::DestructorAtExit
|
||||||
g_chrome_content_renderer_client = LAZY_INSTANCE_INITIALIZER;
|
g_chrome_content_renderer_client = LAZY_INSTANCE_INITIALIZER;
|
||||||
|
|
||||||
|
void InitLogging(const base::CommandLine* command_line) {
|
||||||
|
logging::LogSeverity log_severity = logging::LOGGING_INFO;
|
||||||
|
|
||||||
|
std::string log_severity_str =
|
||||||
|
command_line->GetSwitchValueASCII(switches::kLogSeverity);
|
||||||
|
if (!log_severity_str.empty()) {
|
||||||
|
if (base::EqualsCaseInsensitiveASCII(log_severity_str,
|
||||||
|
switches::kLogSeverity_Verbose)) {
|
||||||
|
log_severity = logging::LOGGING_VERBOSE;
|
||||||
|
} else if (base::EqualsCaseInsensitiveASCII(
|
||||||
|
log_severity_str, switches::kLogSeverity_Warning)) {
|
||||||
|
log_severity = logging::LOGGING_WARNING;
|
||||||
|
} else if (base::EqualsCaseInsensitiveASCII(log_severity_str,
|
||||||
|
switches::kLogSeverity_Error)) {
|
||||||
|
log_severity = logging::LOGGING_ERROR;
|
||||||
|
} else if (base::EqualsCaseInsensitiveASCII(log_severity_str,
|
||||||
|
switches::kLogSeverity_Fatal)) {
|
||||||
|
log_severity = logging::LOGGING_FATAL;
|
||||||
|
} else if (base::EqualsCaseInsensitiveASCII(
|
||||||
|
log_severity_str, switches::kLogSeverity_Disable)) {
|
||||||
|
log_severity = LOGSEVERITY_DISABLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (log_severity == LOGSEVERITY_DISABLE) {
|
||||||
|
// By default, ERROR and FATAL messages will always be output to stderr due
|
||||||
|
// to the kAlwaysPrintErrorLevel value in base/logging.cc. We change the log
|
||||||
|
// level here so that only FATAL messages are output.
|
||||||
|
logging::SetMinLogLevel(logging::LOGGING_FATAL);
|
||||||
|
} else {
|
||||||
|
logging::SetMinLogLevel(log_severity);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Customization of items automatically prepended to log lines.
|
||||||
|
std::string log_items_str =
|
||||||
|
command_line->GetSwitchValueASCII(switches::kLogItems);
|
||||||
|
if (!log_items_str.empty()) {
|
||||||
|
bool enable_log_of_process_id, enable_log_of_thread_id,
|
||||||
|
enable_log_of_time_stamp, enable_log_of_tick_count;
|
||||||
|
enable_log_of_process_id = enable_log_of_thread_id =
|
||||||
|
enable_log_of_time_stamp = enable_log_of_tick_count = false;
|
||||||
|
|
||||||
|
for (const auto& cur_item_to_log :
|
||||||
|
base::SplitStringPiece(log_items_str, ",", base::TRIM_WHITESPACE,
|
||||||
|
base::SPLIT_WANT_NONEMPTY)) {
|
||||||
|
// if "none" mode is present, all items are disabled.
|
||||||
|
if (base::EqualsCaseInsensitiveASCII(cur_item_to_log,
|
||||||
|
switches::kLogItems_None)) {
|
||||||
|
enable_log_of_process_id = enable_log_of_thread_id =
|
||||||
|
enable_log_of_time_stamp = enable_log_of_tick_count = false;
|
||||||
|
break;
|
||||||
|
} else if (base::EqualsCaseInsensitiveASCII(cur_item_to_log,
|
||||||
|
switches::kLogItems_PId)) {
|
||||||
|
enable_log_of_process_id = true;
|
||||||
|
} else if (base::EqualsCaseInsensitiveASCII(cur_item_to_log,
|
||||||
|
switches::kLogItems_TId)) {
|
||||||
|
enable_log_of_thread_id = true;
|
||||||
|
} else if (base::EqualsCaseInsensitiveASCII(
|
||||||
|
cur_item_to_log, switches::kLogItems_TimeStamp)) {
|
||||||
|
enable_log_of_time_stamp = true;
|
||||||
|
} else if (base::EqualsCaseInsensitiveASCII(
|
||||||
|
cur_item_to_log, switches::kLogItems_TickCount)) {
|
||||||
|
enable_log_of_tick_count = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logging::SetLogItems(enable_log_of_process_id, enable_log_of_thread_id,
|
||||||
|
enable_log_of_time_stamp, enable_log_of_tick_count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
ChromeMainDelegateCef::ChromeMainDelegateCef(CefMainRunnerHandler* runner,
|
ChromeMainDelegateCef::ChromeMainDelegateCef(CefMainRunnerHandler* runner,
|
||||||
@ -143,6 +213,70 @@ std::optional<int> ChromeMainDelegateCef::BasicStartupComplete() {
|
|||||||
command_line->AppendSwitchASCII(switches::kLang, "en-US");
|
command_line->AppendSwitchASCII(switches::kLang, "en-US");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!command_line->HasSwitch(switches::kLogFile) &&
|
||||||
|
settings_->log_file.length > 0) {
|
||||||
|
auto log_file = base::FilePath(CefString(&settings_->log_file));
|
||||||
|
command_line->AppendSwitchPath(switches::kLogFile, log_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!command_line->HasSwitch(switches::kLogSeverity) &&
|
||||||
|
settings_->log_severity != LOGSEVERITY_DEFAULT) {
|
||||||
|
std::string log_severity;
|
||||||
|
switch (settings_->log_severity) {
|
||||||
|
case LOGSEVERITY_VERBOSE:
|
||||||
|
log_severity = switches::kLogSeverity_Verbose;
|
||||||
|
break;
|
||||||
|
case LOGSEVERITY_INFO:
|
||||||
|
log_severity = switches::kLogSeverity_Info;
|
||||||
|
break;
|
||||||
|
case LOGSEVERITY_WARNING:
|
||||||
|
log_severity = switches::kLogSeverity_Warning;
|
||||||
|
break;
|
||||||
|
case LOGSEVERITY_ERROR:
|
||||||
|
log_severity = switches::kLogSeverity_Error;
|
||||||
|
break;
|
||||||
|
case LOGSEVERITY_FATAL:
|
||||||
|
log_severity = switches::kLogSeverity_Fatal;
|
||||||
|
break;
|
||||||
|
case LOGSEVERITY_DISABLE:
|
||||||
|
log_severity = switches::kLogSeverity_Disable;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!log_severity.empty()) {
|
||||||
|
command_line->AppendSwitchASCII(switches::kLogSeverity, log_severity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!command_line->HasSwitch(switches::kLogItems) &&
|
||||||
|
settings_->log_items != LOG_ITEMS_DEFAULT) {
|
||||||
|
std::string log_items_str;
|
||||||
|
if (settings_->log_items == LOG_ITEMS_NONE) {
|
||||||
|
log_items_str = std::string(switches::kLogItems_None);
|
||||||
|
} else {
|
||||||
|
std::vector<std::string_view> added_items;
|
||||||
|
if (settings_->log_items & LOG_ITEMS_FLAG_PROCESS_ID) {
|
||||||
|
added_items.emplace_back(switches::kLogItems_PId);
|
||||||
|
}
|
||||||
|
if (settings_->log_items & LOG_ITEMS_FLAG_THREAD_ID) {
|
||||||
|
added_items.emplace_back(switches::kLogItems_TId);
|
||||||
|
}
|
||||||
|
if (settings_->log_items & LOG_ITEMS_FLAG_TIME_STAMP) {
|
||||||
|
added_items.emplace_back(switches::kLogItems_TimeStamp);
|
||||||
|
}
|
||||||
|
if (settings_->log_items & LOG_ITEMS_FLAG_TICK_COUNT) {
|
||||||
|
added_items.emplace_back(switches::kLogItems_TickCount);
|
||||||
|
}
|
||||||
|
if (!added_items.empty()) {
|
||||||
|
log_items_str = base::JoinString(added_items, ",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!log_items_str.empty()) {
|
||||||
|
command_line->AppendSwitchASCII(switches::kLogItems, log_items_str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (settings_->javascript_flags.length > 0) {
|
if (settings_->javascript_flags.length > 0) {
|
||||||
command_line->AppendSwitchASCII(
|
command_line->AppendSwitchASCII(
|
||||||
blink::switches::kJavaScriptFlags,
|
blink::switches::kJavaScriptFlags,
|
||||||
@ -212,6 +346,9 @@ std::optional<int> ChromeMainDelegateCef::BasicStartupComplete() {
|
|||||||
std::ignore = commandLinePtr->Detach(nullptr);
|
std::ignore = commandLinePtr->Detach(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Call as early as possible.
|
||||||
|
InitLogging(command_line);
|
||||||
|
|
||||||
#if BUILDFLAG(IS_MAC)
|
#if BUILDFLAG(IS_MAC)
|
||||||
util_mac::BasicStartupComplete();
|
util_mac::BasicStartupComplete();
|
||||||
#endif
|
#endif
|
||||||
@ -264,6 +401,23 @@ void ChromeMainDelegateCef::PreSandboxStartup() {
|
|||||||
base::PathService::Override(ui::DIR_LOCALES, locales_dir);
|
base::PathService::Override(ui::DIR_LOCALES, locales_dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !BUILDFLAG(IS_WIN)
|
||||||
|
// Call after InitLogging() potentially changes values in
|
||||||
|
// chrome/app/chrome_main_delegate.cc.
|
||||||
|
InitLogging(command_line);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChromeMainDelegateCef::SandboxInitialized(
|
||||||
|
const std::string& process_type) {
|
||||||
|
ChromeMainDelegate::SandboxInitialized(process_type);
|
||||||
|
|
||||||
|
#if BUILDFLAG(IS_WIN)
|
||||||
|
// Call after InitLogging() potentially changes values in
|
||||||
|
// chrome/app/chrome_main_delegate.cc.
|
||||||
|
InitLogging(base::CommandLine::ForCurrentProcess());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<int> ChromeMainDelegateCef::PreBrowserMain() {
|
std::optional<int> ChromeMainDelegateCef::PreBrowserMain() {
|
||||||
|
@ -37,6 +37,7 @@ class ChromeMainDelegateCef : public ChromeMainDelegate,
|
|||||||
// ChromeMainDelegate overrides.
|
// ChromeMainDelegate overrides.
|
||||||
std::optional<int> BasicStartupComplete() override;
|
std::optional<int> BasicStartupComplete() override;
|
||||||
void PreSandboxStartup() override;
|
void PreSandboxStartup() override;
|
||||||
|
void SandboxInitialized(const std::string& process_type) override;
|
||||||
std::optional<int> PreBrowserMain() override;
|
std::optional<int> PreBrowserMain() override;
|
||||||
std::optional<int> PostEarlyInitialization(InvokedIn invoked_in) override;
|
std::optional<int> PostEarlyInitialization(InvokedIn invoked_in) override;
|
||||||
absl::variant<int, content::MainFunctionParams> RunProcess(
|
absl::variant<int, content::MainFunctionParams> RunProcess(
|
||||||
|
@ -342,6 +342,11 @@ patches = [
|
|||||||
# https://github.com/chromiumembedded/cef/issues/2969
|
# https://github.com/chromiumembedded/cef/issues/2969
|
||||||
'name': 'chrome_browser_profile_menu',
|
'name': 'chrome_browser_profile_menu',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
# chrome: Enable logging by default for Release builds.
|
||||||
|
# https://github.com/chromiumembedded/cef/issues/2969
|
||||||
|
'name': 'chrome_common_logging',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
# alloy: Don't require heap profiler for utility processes.
|
# alloy: Don't require heap profiler for utility processes.
|
||||||
# Avoids a DCHECK added in https://crrev.com/c21e9f71d1f2e
|
# Avoids a DCHECK added in https://crrev.com/c21e9f71d1f2e
|
||||||
|
35
patch/patches/chrome_common_logging.patch
Normal file
35
patch/patches/chrome_common_logging.patch
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
diff --git chrome/common/features.gni chrome/common/features.gni
|
||||||
|
index 01367ff6efd6c..975ea8e446dce 100644
|
||||||
|
--- chrome/common/features.gni
|
||||||
|
+++ chrome/common/features.gni
|
||||||
|
@@ -7,6 +7,7 @@ import("//build/config/chromeos/ui_mode.gni")
|
||||||
|
import("//build/config/compiler/compiler.gni")
|
||||||
|
import("//build/config/dcheck_always_on.gni")
|
||||||
|
import("//build/config/features.gni")
|
||||||
|
+import("//cef/libcef/features/features.gni")
|
||||||
|
import("//components/compose/features.gni")
|
||||||
|
import("//components/feed/features.gni")
|
||||||
|
import("//components/nacl/features.gni")
|
||||||
|
@@ -31,7 +32,7 @@ assert(use_blink, "Chromium without blink shouldn't use anything in //chrome")
|
||||||
|
declare_args() {
|
||||||
|
# Enables the build to have logging enabled by default.
|
||||||
|
# This is intended for use only in developer builds.
|
||||||
|
- chrome_enable_logging_by_default = is_debug
|
||||||
|
+ chrome_enable_logging_by_default = is_debug || enable_cef
|
||||||
|
|
||||||
|
# Platforms where Chrome x509 server certificate enterprise policies are
|
||||||
|
# supported. This must must match the supported_on/future_on list of the
|
||||||
|
@@ -90,11 +91,13 @@ declare_args() {
|
||||||
|
# optimize_webui was moved to ui/base/ui_features.gni
|
||||||
|
}
|
||||||
|
|
||||||
|
+if (!enable_cef) {
|
||||||
|
# Logging must be disabled by default in all official builds (including special
|
||||||
|
# DCHECK-enabled builds). Logging is enabled by default for debug builds, and
|
||||||
|
# may be selectively enabled by default for release builds.
|
||||||
|
assert(!chrome_enable_logging_by_default || !is_official_build,
|
||||||
|
"Logging must be disabled by default in Official builds")
|
||||||
|
+}
|
||||||
|
|
||||||
|
# Use brlapi from brltty for braille display support.
|
||||||
|
use_brlapi = is_chromeos_ash
|
Loading…
x
Reference in New Issue
Block a user