From 9546ff9c77552e8c568226fe20964205ddb99cb6 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Mon, 25 Jun 2012 17:52:54 +0000 Subject: [PATCH] Add support for customizing log file path and log severity level (issue #613). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@707 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- include/internal/cef_types.h | 31 +++++++++- libcef/browser/content_browser_client.cc | 2 + libcef/common/cef_switches.cc | 22 +++++-- libcef/common/cef_switches.h | 8 +++ libcef/common/main_delegate.cc | 74 ++++++++++++++++++++++++ tests/cefclient/cefclient.cpp | 29 ---------- tests/cefclient/client_switches.cpp | 8 --- tests/cefclient/client_switches.h | 8 --- tests/unittests/test_suite.cc | 30 ---------- 9 files changed, 130 insertions(+), 82 deletions(-) diff --git a/include/internal/cef_types.h b/include/internal/cef_types.h index eb99c1e0b..a844cea9e 100644 --- a/include/internal/cef_types.h +++ b/include/internal/cef_types.h @@ -92,12 +92,39 @@ extern "C" { // Log severity levels. /// enum cef_log_severity_t { - LOGSEVERITY_VERBOSE = -1, + /// + // Default logging (currently INFO logging). + /// + LOGSEVERITY_DEFAULT, + + /// + // Verbose logging. + /// + LOGSEVERITY_VERBOSE, + + /// + // INFO logging. + /// LOGSEVERITY_INFO, + + /// + // WARNING logging. + /// LOGSEVERITY_WARNING, + + /// + // ERROR logging. + /// LOGSEVERITY_ERROR, + + /// + // ERROR_REPORT logging. + /// LOGSEVERITY_ERROR_REPORT, - // Disables logging completely. + + /// + // Completely disable logging. + /// LOGSEVERITY_DISABLE = 99 }; diff --git a/libcef/browser/content_browser_client.cc b/libcef/browser/content_browser_client.cc index 539134b68..138f32f1c 100644 --- a/libcef/browser/content_browser_client.cc +++ b/libcef/browser/content_browser_client.cc @@ -97,6 +97,8 @@ void CefContentBrowserClient::AppendExtraCommandLineSwitches( // Propagate the following switches to the renderer command line (along // with any associated values) if present in the browser command line. static const char* const kSwitchNames[] = { + switches::kLogFile, + switches::kLogSeverity, switches::kProductVersion, switches::kLocale, switches::kPackFilePath, diff --git a/libcef/common/cef_switches.cc b/libcef/common/cef_switches.cc index 2d03b2e09..a626df51e 100644 --- a/libcef/common/cef_switches.cc +++ b/libcef/common/cef_switches.cc @@ -7,18 +7,30 @@ namespace switches { // Product version string. -const char kProductVersion[] = "product-version"; +const char kProductVersion[] = "product-version"; // Locale string. -const char kLocale[] = "locale"; +const char kLocale[] = "locale"; + +// Log file path. +const char kLogFile[] = "log-file"; + +// Severity of messages to log. +const char kLogSeverity[] = "log-severity"; +const char kLogSeverity_Verbose[] = "verbose"; +const char kLogSeverity_Info[] = "info"; +const char kLogSeverity_Warning[] = "warning"; +const char kLogSeverity_Error[] = "error"; +const char kLogSeverity_ErrorReport[] = "error-report"; +const char kLogSeverity_Disable[] = "disable"; // Path to cef.pak file. -const char kPackFilePath[] = "pack-file-path"; +const char kPackFilePath[] = "pack-file-path"; // Path to locales directory. -const char kLocalesDirPath[] = "locales-dir-path"; +const char kLocalesDirPath[] = "locales-dir-path"; // Path to locales directory. -const char kPackLoadingDisabled[] = "pack-loading-disabled"; +const char kPackLoadingDisabled[] = "pack-loading-disabled"; } // namespace switches diff --git a/libcef/common/cef_switches.h b/libcef/common/cef_switches.h index 6fc7e22dd..27ec00474 100644 --- a/libcef/common/cef_switches.h +++ b/libcef/common/cef_switches.h @@ -12,6 +12,14 @@ namespace switches { extern const char kProductVersion[]; extern const char kLocale[]; +extern const char kLogFile[]; +extern const char kLogSeverity[]; +extern const char kLogSeverity_Verbose[]; +extern const char kLogSeverity_Info[]; +extern const char kLogSeverity_Warning[]; +extern const char kLogSeverity_Error[]; +extern const char kLogSeverity_ErrorReport[]; +extern const char kLogSeverity_Disable[]; extern const char kPackFilePath[]; extern const char kLocalesDirPath[]; extern const char kPackLoadingDisabled[]; diff --git a/libcef/common/main_delegate.cc b/libcef/common/main_delegate.cc index 8b6cf8eed..fe763f8cc 100644 --- a/libcef/common/main_delegate.cc +++ b/libcef/common/main_delegate.cc @@ -14,6 +14,7 @@ #include "base/file_util.h" #include "base/path_service.h" #include "base/string_number_conversions.h" +#include "base/string_util.h" #include "base/synchronization/waitable_event.h" #include "base/threading/thread.h" #include "content/public/browser/browser_main_runner.h" @@ -185,6 +186,38 @@ bool CefMainDelegate::BasicStartupComplete(int* exit_code) { CefString(&settings.locale)); } + if (settings.log_file.length > 0) { + FilePath file_path = FilePath(CefString(&settings.log_file)); + if (!file_path.empty()) + command_line->AppendSwitchPath(switches::kLogFile, file_path); + } + + if (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_ERROR_REPORT: + log_severity = switches::kLogSeverity_ErrorReport; + break; + case LOGSEVERITY_DISABLE: + log_severity = switches::kLogSeverity_Disable; + break; + } + if (!log_severity.empty()) + command_line->AppendSwitchASCII(switches::kLogSeverity, log_severity); + } + if (settings.javascript_flags.length > 0) { command_line->AppendSwitchASCII(switches::kJavaScriptFlags, CefString(&settings.javascript_flags)); @@ -226,6 +259,47 @@ bool CefMainDelegate::BasicStartupComplete(int* exit_code) { commandLinePtr->Detach(NULL); } + // Initialize logging. + FilePath log_file = command_line->GetSwitchValuePath(switches::kLogFile); + std::string log_severity_str = + command_line->GetSwitchValueASCII(switches::kLogSeverity); + + logging::LogSeverity log_severity = logging::LOG_INFO; + if (!log_severity_str.empty()) { + if (LowerCaseEqualsASCII(log_severity_str, + switches::kLogSeverity_Verbose)) { + log_severity = logging::LOG_VERBOSE; + } else if (LowerCaseEqualsASCII(log_severity_str, + switches::kLogSeverity_Warning)) { + log_severity = logging::LOG_WARNING; + } else if (LowerCaseEqualsASCII(log_severity_str, + switches::kLogSeverity_Error)) { + log_severity = logging::LOG_ERROR; + } else if (LowerCaseEqualsASCII(log_severity_str, + switches::kLogSeverity_ErrorReport)) { + log_severity = logging::LOG_ERROR_REPORT; + } else if (LowerCaseEqualsASCII(log_severity_str, + switches::kLogSeverity_Disable)) { + log_severity = LOGSEVERITY_DISABLE; + } + } + + logging::LoggingDestination logging_dest; + if (log_severity == LOGSEVERITY_DISABLE) { + logging_dest = logging::LOG_NONE; + } else { +#if defined(OS_WIN) + logging_dest = logging::LOG_ONLY_TO_FILE; +#else + logging_dest = logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG; +#endif + logging::SetMinLogLevel(log_severity); + } + + logging::InitLogging(log_file.value().c_str(), logging_dest, + logging::DONT_LOCK_LOG_FILE, logging::APPEND_TO_OLD_LOG_FILE, + logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); + content::SetContentClient(&content_client_); return false; diff --git a/tests/cefclient/cefclient.cpp b/tests/cefclient/cefclient.cpp index 8a890a727..caa0683f5 100644 --- a/tests/cefclient/cefclient.cpp +++ b/tests/cefclient/cefclient.cpp @@ -76,35 +76,6 @@ void AppGetSettings(CefSettings& settings, CefRefPtr app) { CefString(&settings.cache_path) = g_command_line->GetSwitchValue(cefclient::kCachePath); - CefString(&settings.log_file) = - g_command_line->GetSwitchValue(cefclient::kLogFile); - - { - std::string str = g_command_line->GetSwitchValue(cefclient::kLogSeverity); - bool invalid = false; - if (!str.empty()) { - if (str == cefclient::kLogSeverity_Verbose) - settings.log_severity = LOGSEVERITY_VERBOSE; - else if (str == cefclient::kLogSeverity_Info) - settings.log_severity = LOGSEVERITY_INFO; - else if (str == cefclient::kLogSeverity_Warning) - settings.log_severity = LOGSEVERITY_WARNING; - else if (str == cefclient::kLogSeverity_Error) - settings.log_severity = LOGSEVERITY_ERROR; - else if (str == cefclient::kLogSeverity_ErrorReport) - settings.log_severity = LOGSEVERITY_ERROR_REPORT; - else if (str == cefclient::kLogSeverity_Disable) - settings.log_severity = LOGSEVERITY_DISABLE; - else - invalid = true; - } - if (str.empty() || invalid) { -#ifdef NDEBUG - // Only log error messages and higher in release build. - settings.log_severity = LOGSEVERITY_ERROR; -#endif - } - } // Retrieve command-line proxy configuration, if any. bool has_proxy = false; diff --git a/tests/cefclient/client_switches.cpp b/tests/cefclient/client_switches.cpp index 8e91d29d4..28eb637d5 100644 --- a/tests/cefclient/client_switches.cpp +++ b/tests/cefclient/client_switches.cpp @@ -11,14 +11,6 @@ namespace cefclient { // CefSettings attributes. const char kMultiThreadedMessageLoop[] = "multi-threaded-message-loop"; const char kCachePath[] = "cache-path"; -const char kLogFile[] = "log-file"; -const char kLogSeverity[] = "log-severity"; -const char kLogSeverity_Verbose[] = "verbose"; -const char kLogSeverity_Info[] = "info"; -const char kLogSeverity_Warning[] = "warning"; -const char kLogSeverity_Error[] = "error"; -const char kLogSeverity_ErrorReport[] = "error-report"; -const char kLogSeverity_Disable[] = "disable"; // CefBrowserSettings attributes. const char kRemoteFontsDisabled[] = "remote-fonts-disabled"; diff --git a/tests/cefclient/client_switches.h b/tests/cefclient/client_switches.h index 07d3c0fdb..12381c126 100644 --- a/tests/cefclient/client_switches.h +++ b/tests/cefclient/client_switches.h @@ -13,14 +13,6 @@ namespace cefclient { // CefSettings attributes. extern const char kMultiThreadedMessageLoop[]; extern const char kCachePath[]; -extern const char kLogFile[]; -extern const char kLogSeverity[]; -extern const char kLogSeverity_Verbose[]; -extern const char kLogSeverity_Info[]; -extern const char kLogSeverity_Warning[]; -extern const char kLogSeverity_Error[]; -extern const char kLogSeverity_ErrorReport[]; -extern const char kLogSeverity_Disable[]; // CefBrowserSettings attributes. extern const char kRemoteFontsDisabled[]; diff --git a/tests/unittests/test_suite.cc b/tests/unittests/test_suite.cc index 284df6701..4a65035fc 100644 --- a/tests/unittests/test_suite.cc +++ b/tests/unittests/test_suite.cc @@ -48,36 +48,6 @@ void CefTestSuite::GetSettings(CefSettings& settings) { CefString(&settings.cache_path) = commandline_->GetSwitchValueASCII(cefclient::kCachePath); - CefString(&settings.log_file) = - commandline_->GetSwitchValueASCII(cefclient::kLogFile); - - { - std::string str = - commandline_->GetSwitchValueASCII(cefclient::kLogSeverity); - bool invalid = false; - if (!str.empty()) { - if (str == cefclient::kLogSeverity_Verbose) - settings.log_severity = LOGSEVERITY_VERBOSE; - else if (str == cefclient::kLogSeverity_Info) - settings.log_severity = LOGSEVERITY_INFO; - else if (str == cefclient::kLogSeverity_Warning) - settings.log_severity = LOGSEVERITY_WARNING; - else if (str == cefclient::kLogSeverity_Error) - settings.log_severity = LOGSEVERITY_ERROR; - else if (str == cefclient::kLogSeverity_ErrorReport) - settings.log_severity = LOGSEVERITY_ERROR_REPORT; - else if (str == cefclient::kLogSeverity_Disable) - settings.log_severity = LOGSEVERITY_DISABLE; - else - invalid = true; - } - if (str.empty() || invalid) { -#ifdef NDEBUG - // Only log error messages and higher in release build. - settings.log_severity = LOGSEVERITY_ERROR; -#endif - } - } // Always expose the V8 gc() function to give tests finer-grained control over // memory management.