diff --git a/include/cef.h b/include/cef.h index 3f24af675..ba4813a0b 100644 --- a/include/cef.h +++ b/include/cef.h @@ -1646,6 +1646,7 @@ public: cef_string_clear(&locale); if(extra_plugin_paths) cef_string_list_free(extra_plugin_paths); + cef_string_clear(&log_file); Init(); } @@ -1680,6 +1681,9 @@ public: extra_plugin_paths = r.extra_plugin_paths ? cef_string_list_copy(r.extra_plugin_paths) : NULL; + cef_string_copy(r.log_file.str, r.log_file.length, &log_file); + log_severity = r.log_severity; + return *this; } diff --git a/include/cef_types.h b/include/cef_types.h index ba31a7fcf..712a48d84 100644 --- a/include/cef_types.h +++ b/include/cef_types.h @@ -54,6 +54,18 @@ typedef long long int64; extern "C" { #endif +// Log severity levels. +enum cef_log_severity_t +{ + LOGSEVERITY_VERBOSE = -1, + LOGSEVERITY_INFO, + LOGSEVERITY_WARNING, + LOGSEVERITY_ERROR, + LOGSEVERITY_ERROR_REPORT, + // Disables logging completely. + LOGSEVERITY_DISABLE = 99 +}; + // Initialization settings. Specify NULL or 0 to get the recommended default // values. typedef struct _cef_settings_t @@ -87,6 +99,15 @@ typedef struct _cef_settings_t // List of file system paths that will be searched by the browser to locate // plugins. This is in addition to the default search paths. cef_string_list_t extra_plugin_paths; + + // The directory and file name to use for the debug log. If empty, the + // default name of "debug.log" will be used and the file will be written + // to the application directory. + cef_string_t log_file; + + // The log severity. Only messages of this severity level or higher will be + // logged. + cef_log_severity_t log_severity; } cef_settings_t; // Browser initialization settings. Specify NULL or 0 to get the recommended diff --git a/libcef/cef_process_ui_thread.cc b/libcef/cef_process_ui_thread.cc index fc694138b..2de55966e 100644 --- a/libcef/cef_process_ui_thread.cc +++ b/libcef/cef_process_ui_thread.cc @@ -66,14 +66,29 @@ CefProcessUIThread::~CefProcessUIThread() { void CefProcessUIThread::Init() { PlatformInit(); -#ifndef _DEBUG - // Only log error messages and above in release build. - logging::SetMinLogLevel(logging::LOG_ERROR); -#endif - // Initialize the global CommandLine object. CommandLine::Init(0, NULL); + const CefSettings& settings = _Context->settings(); + + // Initialize logging. + logging::LoggingDestination logging_dest; + if (settings.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(settings.log_severity); + } + + FilePath log_file = FilePath(CefString(&settings.log_file)); + 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); + // Initialize WebKit. webkit_init_ = new BrowserWebKitInit(); @@ -123,8 +138,6 @@ void CefProcessUIThread::Init() { _Context->set_storage_context(new DOMStorageContext()); } - const CefSettings& settings = _Context->settings(); - if (settings.user_agent.length > 0) webkit_glue::SetUserAgent(CefString(&settings.user_agent)); diff --git a/tests/cefclient/cefclient_win.cpp b/tests/cefclient/cefclient_win.cpp index ffae9bc83..06edd17bc 100644 --- a/tests/cefclient/cefclient_win.cpp +++ b/tests/cefclient/cefclient_win.cpp @@ -69,6 +69,11 @@ int APIENTRY wWinMain(HINSTANCE hInstance, // Specify a cache path value. //CefString(&settings.cache_path).FromASCII("c:\\temp\\cache"); +#ifndef _DEBUG + // Only log error messages and higher in release build. + settings.log_severity = LOGSEVERITY_ERROR; +#endif + #ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP // Initialize the CEF with messages processed using the current application's // message loop.