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

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