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
This commit is contained in:
Marshall Greenblatt 2012-06-25 17:52:54 +00:00
parent b7d0517886
commit 9546ff9c77
9 changed files with 130 additions and 82 deletions

View File

@ -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
};

View File

@ -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,

View File

@ -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

View File

@ -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[];

View File

@ -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;

View File

@ -76,35 +76,6 @@ void AppGetSettings(CefSettings& settings, CefRefPtr<ClientApp> 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;

View File

@ -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";

View File

@ -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[];

View File

@ -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.