mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Use a reasonable default log file location if none is specified (issue #1757)
This commit is contained in:
@ -262,10 +262,12 @@ typedef struct _cef_settings_t {
|
|||||||
cef_string_t locale;
|
cef_string_t locale;
|
||||||
|
|
||||||
///
|
///
|
||||||
// The directory and file name to use for the debug log. If empty, the
|
// The directory and file name to use for the debug log. If empty a default
|
||||||
// default name of "debug.log" will be used and the file will be written
|
// log file name and location will be used. On Windows and Linux a "debug.log"
|
||||||
// to the application directory. Also configurable using the "log-file"
|
// file will be written in the main executable directory. On Mac OS X a
|
||||||
// command-line switch.
|
// "~/Library/Logs/<app name>_debug.log" file will be written where <app name>
|
||||||
|
// is the name of the main app executable. Also configurable using the
|
||||||
|
// "log-file" command-line switch.
|
||||||
///
|
///
|
||||||
cef_string_t log_file;
|
cef_string_t log_file;
|
||||||
|
|
||||||
|
@ -106,22 +106,32 @@ base::FilePath GetResourcesFilePath() {
|
|||||||
return GetFrameworkBundlePath().Append(FILE_PATH_LITERAL("Resources"));
|
return GetFrameworkBundlePath().Append(FILE_PATH_LITERAL("Resources"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Retrieve the name of the running executable.
|
||||||
|
std::string GetExecutableName() {
|
||||||
|
base::FilePath path;
|
||||||
|
PathService::Get(base::FILE_EXE, &path);
|
||||||
|
return path.BaseName().value();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use a "~/Library/Logs/<app name>_debug.log" file where <app name> is the name
|
||||||
|
// of the running executable.
|
||||||
|
base::FilePath GetDefaultLogFile() {
|
||||||
|
return base::mac::GetUserLibraryPath()
|
||||||
|
.Append(FILE_PATH_LITERAL("Logs"))
|
||||||
|
.Append(FILE_PATH_LITERAL(GetExecutableName() + "_debug.log"));
|
||||||
|
}
|
||||||
|
|
||||||
void OverrideFrameworkBundlePath() {
|
void OverrideFrameworkBundlePath() {
|
||||||
base::mac::SetOverrideFrameworkBundlePath(GetFrameworkBundlePath());
|
base::mac::SetOverrideFrameworkBundlePath(GetFrameworkBundlePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverrideChildProcessPath() {
|
void OverrideChildProcessPath() {
|
||||||
// Retrieve the name of the running executable.
|
const std::string& exe_name = GetExecutableName();
|
||||||
base::FilePath path;
|
|
||||||
PathService::Get(base::FILE_EXE, &path);
|
|
||||||
|
|
||||||
std::string name = path.BaseName().value();
|
|
||||||
|
|
||||||
base::FilePath helper_path = GetFrameworksPath()
|
base::FilePath helper_path = GetFrameworksPath()
|
||||||
.Append(FILE_PATH_LITERAL(name+" Helper.app"))
|
.Append(FILE_PATH_LITERAL(exe_name + " Helper.app"))
|
||||||
.Append(FILE_PATH_LITERAL("Contents"))
|
.Append(FILE_PATH_LITERAL("Contents"))
|
||||||
.Append(FILE_PATH_LITERAL("MacOS"))
|
.Append(FILE_PATH_LITERAL("MacOS"))
|
||||||
.Append(FILE_PATH_LITERAL(name+" Helper"));
|
.Append(FILE_PATH_LITERAL(exe_name + " Helper"));
|
||||||
|
|
||||||
PathService::Override(content::CHILD_PROCESS_EXE, helper_path);
|
PathService::Override(content::CHILD_PROCESS_EXE, helper_path);
|
||||||
}
|
}
|
||||||
@ -134,6 +144,13 @@ base::FilePath GetResourcesFilePath() {
|
|||||||
return pak_dir;
|
return pak_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use a "debug.log" file in the running executable's directory.
|
||||||
|
base::FilePath GetDefaultLogFile() {
|
||||||
|
base::FilePath log_path;
|
||||||
|
PathService::Get(base::DIR_EXE, &log_path);
|
||||||
|
return log_path.Append(FILE_PATH_LITERAL("debug.log"));
|
||||||
|
}
|
||||||
|
|
||||||
#endif // !defined(OS_MACOSX)
|
#endif // !defined(OS_MACOSX)
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
@ -360,11 +377,20 @@ bool CefMainDelegate::BasicStartupComplete(int* exit_code) {
|
|||||||
command_line->AppendSwitchASCII(switches::kLang, "en-US");
|
command_line->AppendSwitchASCII(switches::kLang, "en-US");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.log_file.length > 0) {
|
base::FilePath log_file;
|
||||||
base::FilePath file_path = base::FilePath(CefString(&settings.log_file));
|
bool has_log_file_cmdline = false;
|
||||||
if (!file_path.empty())
|
if (settings.log_file.length > 0)
|
||||||
command_line->AppendSwitchPath(switches::kLogFile, file_path);
|
log_file = base::FilePath(CefString(&settings.log_file));
|
||||||
|
if (log_file.empty() && command_line->HasSwitch(switches::kLogFile)) {
|
||||||
|
log_file = command_line->GetSwitchValuePath(switches::kLogFile);
|
||||||
|
if (!log_file.empty())
|
||||||
|
has_log_file_cmdline = true;
|
||||||
}
|
}
|
||||||
|
if (log_file.empty())
|
||||||
|
log_file = GetDefaultLogFile();
|
||||||
|
DCHECK(!log_file.empty());
|
||||||
|
if (!has_log_file_cmdline)
|
||||||
|
command_line->AppendSwitchPath(switches::kLogFile, log_file);
|
||||||
|
|
||||||
if (settings.log_severity != LOGSEVERITY_DEFAULT) {
|
if (settings.log_severity != LOGSEVERITY_DEFAULT) {
|
||||||
std::string log_severity;
|
std::string log_severity;
|
||||||
@ -444,9 +470,12 @@ bool CefMainDelegate::BasicStartupComplete(int* exit_code) {
|
|||||||
|
|
||||||
// Initialize logging.
|
// Initialize logging.
|
||||||
logging::LoggingSettings log_settings;
|
logging::LoggingSettings log_settings;
|
||||||
|
|
||||||
const base::FilePath& log_file =
|
const base::FilePath& log_file =
|
||||||
command_line->GetSwitchValuePath(switches::kLogFile);
|
command_line->GetSwitchValuePath(switches::kLogFile);
|
||||||
|
DCHECK(!log_file.empty());
|
||||||
log_settings.log_file = log_file.value().c_str();
|
log_settings.log_file = log_file.value().c_str();
|
||||||
|
|
||||||
log_settings.lock_log = logging::DONT_LOCK_LOG_FILE;
|
log_settings.lock_log = logging::DONT_LOCK_LOG_FILE;
|
||||||
log_settings.delete_old = logging::APPEND_TO_OLD_LOG_FILE;
|
log_settings.delete_old = logging::APPEND_TO_OLD_LOG_FILE;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user