From 995dd0ba19c83744ffdb5e45e0fb8b54fa7b9d1e Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Tue, 29 Jan 2019 14:53:17 -0500 Subject: [PATCH] Suppress ERROR messages with log-severity=disable (issue #2581) Also expose FATAL severity level. --- include/internal/cef_types.h | 15 +++++++++++---- libcef/common/cef_switches.cc | 1 + libcef/common/cef_switches.h | 1 + libcef/common/main_delegate.cc | 10 ++++++++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/include/internal/cef_types.h b/include/internal/cef_types.h index fb5f02cc6..f47e8608d 100644 --- a/include/internal/cef_types.h +++ b/include/internal/cef_types.h @@ -115,7 +115,13 @@ typedef enum { LOGSEVERITY_ERROR, /// - // Completely disable logging. + // FATAL logging. + /// + LOGSEVERITY_FATAL, + + /// + // Disable logging to file for all messages, and to stderr for messages with + // severity less than FATAL. /// LOGSEVERITY_DISABLE = 99 } cef_log_severity_t; @@ -290,9 +296,10 @@ typedef struct _cef_settings_t { /// // The log severity. Only messages of this severity level or higher will be - // logged. Also configurable using the "log-severity" command-line switch with - // a value of "verbose", "info", "warning", "error", "error-report" or - // "disable". + // logged. When set to DISABLE no messages will be written to the log file, + // but FATAL messages will still be output to stderr. Also configurable using + // the "log-severity" command-line switch with a value of "verbose", "info", + // "warning", "error", "fatal" or "disable". /// cef_log_severity_t log_severity; diff --git a/libcef/common/cef_switches.cc b/libcef/common/cef_switches.cc index 3b7f4f872..520abcd25 100644 --- a/libcef/common/cef_switches.cc +++ b/libcef/common/cef_switches.cc @@ -12,6 +12,7 @@ const char kLogSeverity_Verbose[] = "verbose"; const char kLogSeverity_Info[] = "info"; const char kLogSeverity_Warning[] = "warning"; const char kLogSeverity_Error[] = "error"; +const char kLogSeverity_Fatal[] = "fatal"; const char kLogSeverity_Disable[] = "disable"; // Path to resources directory. diff --git a/libcef/common/cef_switches.h b/libcef/common/cef_switches.h index 8e15d6100..ea00cd841 100644 --- a/libcef/common/cef_switches.h +++ b/libcef/common/cef_switches.h @@ -17,6 +17,7 @@ extern const char kLogSeverity_Verbose[]; extern const char kLogSeverity_Info[]; extern const char kLogSeverity_Warning[]; extern const char kLogSeverity_Error[]; +extern const char kLogSeverity_Fatal[]; extern const char kLogSeverity_Disable[]; extern const char kResourcesDirPath[]; extern const char kLocalesDirPath[]; diff --git a/libcef/common/main_delegate.cc b/libcef/common/main_delegate.cc index e981036cb..348dc41cc 100644 --- a/libcef/common/main_delegate.cc +++ b/libcef/common/main_delegate.cc @@ -422,6 +422,9 @@ bool CefMainDelegate::BasicStartupComplete(int* exit_code) { 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; @@ -529,6 +532,9 @@ bool CefMainDelegate::BasicStartupComplete(int* exit_code) { } else if (base::LowerCaseEqualsASCII(log_severity_str, switches::kLogSeverity_Error)) { log_severity = logging::LOG_ERROR; + } else if (base::LowerCaseEqualsASCII(log_severity_str, + switches::kLogSeverity_Fatal)) { + log_severity = logging::LOG_FATAL; } else if (base::LowerCaseEqualsASCII(log_severity_str, switches::kLogSeverity_Disable)) { log_severity = LOGSEVERITY_DISABLE; @@ -537,6 +543,10 @@ bool CefMainDelegate::BasicStartupComplete(int* exit_code) { if (log_severity == LOGSEVERITY_DISABLE) { log_settings.logging_dest = logging::LOG_NONE; + // 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::LOG_FATAL); } else { log_settings.logging_dest = logging::LOG_TO_ALL; logging::SetMinLogLevel(log_severity);