Suppress ERROR messages with log-severity=disable (issue #2581)

Also expose FATAL severity level.
This commit is contained in:
Marshall Greenblatt 2019-01-29 14:53:17 -05:00
parent f962b5863e
commit 995dd0ba19
4 changed files with 23 additions and 4 deletions

View File

@ -115,7 +115,13 @@ typedef enum {
LOGSEVERITY_ERROR, 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 LOGSEVERITY_DISABLE = 99
} cef_log_severity_t; } 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 // The log severity. Only messages of this severity level or higher will be
// logged. Also configurable using the "log-severity" command-line switch with // logged. When set to DISABLE no messages will be written to the log file,
// a value of "verbose", "info", "warning", "error", "error-report" or // but FATAL messages will still be output to stderr. Also configurable using
// "disable". // the "log-severity" command-line switch with a value of "verbose", "info",
// "warning", "error", "fatal" or "disable".
/// ///
cef_log_severity_t log_severity; cef_log_severity_t log_severity;

View File

@ -12,6 +12,7 @@ const char kLogSeverity_Verbose[] = "verbose";
const char kLogSeverity_Info[] = "info"; const char kLogSeverity_Info[] = "info";
const char kLogSeverity_Warning[] = "warning"; const char kLogSeverity_Warning[] = "warning";
const char kLogSeverity_Error[] = "error"; const char kLogSeverity_Error[] = "error";
const char kLogSeverity_Fatal[] = "fatal";
const char kLogSeverity_Disable[] = "disable"; const char kLogSeverity_Disable[] = "disable";
// Path to resources directory. // Path to resources directory.

View File

@ -17,6 +17,7 @@ extern const char kLogSeverity_Verbose[];
extern const char kLogSeverity_Info[]; extern const char kLogSeverity_Info[];
extern const char kLogSeverity_Warning[]; extern const char kLogSeverity_Warning[];
extern const char kLogSeverity_Error[]; extern const char kLogSeverity_Error[];
extern const char kLogSeverity_Fatal[];
extern const char kLogSeverity_Disable[]; extern const char kLogSeverity_Disable[];
extern const char kResourcesDirPath[]; extern const char kResourcesDirPath[];
extern const char kLocalesDirPath[]; extern const char kLocalesDirPath[];

View File

@ -422,6 +422,9 @@ bool CefMainDelegate::BasicStartupComplete(int* exit_code) {
case LOGSEVERITY_ERROR: case LOGSEVERITY_ERROR:
log_severity = switches::kLogSeverity_Error; log_severity = switches::kLogSeverity_Error;
break; break;
case LOGSEVERITY_FATAL:
log_severity = switches::kLogSeverity_Fatal;
break;
case LOGSEVERITY_DISABLE: case LOGSEVERITY_DISABLE:
log_severity = switches::kLogSeverity_Disable; log_severity = switches::kLogSeverity_Disable;
break; break;
@ -529,6 +532,9 @@ bool CefMainDelegate::BasicStartupComplete(int* exit_code) {
} else if (base::LowerCaseEqualsASCII(log_severity_str, } else if (base::LowerCaseEqualsASCII(log_severity_str,
switches::kLogSeverity_Error)) { switches::kLogSeverity_Error)) {
log_severity = logging::LOG_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, } else if (base::LowerCaseEqualsASCII(log_severity_str,
switches::kLogSeverity_Disable)) { switches::kLogSeverity_Disable)) {
log_severity = LOGSEVERITY_DISABLE; log_severity = LOGSEVERITY_DISABLE;
@ -537,6 +543,10 @@ bool CefMainDelegate::BasicStartupComplete(int* exit_code) {
if (log_severity == LOGSEVERITY_DISABLE) { if (log_severity == LOGSEVERITY_DISABLE) {
log_settings.logging_dest = logging::LOG_NONE; 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 { } else {
log_settings.logging_dest = logging::LOG_TO_ALL; log_settings.logging_dest = logging::LOG_TO_ALL;
logging::SetMinLogLevel(log_severity); logging::SetMinLogLevel(log_severity);