diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 37ff0507d761..d8ce8170fb0b 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -375,6 +375,8 @@ int GetPathConstant(const std::string& name) { return brightray::DIR_CACHE; else if (name == "userCache") return brightray::DIR_USER_CACHE; + else if (name == "logs") + return brightray::DIR_APP_LOGS; else if (name == "home") return base::DIR_HOME; else if (name == "temp") diff --git a/brightray/browser/brightray_paths.h b/brightray/browser/brightray_paths.h index b12b10d08f3c..56525baeaab7 100644 --- a/brightray/browser/brightray_paths.h +++ b/brightray/browser/brightray_paths.h @@ -22,6 +22,7 @@ enum { DIR_USER_DATA = PATH_START, // Directory where user data can be written. DIR_USER_CACHE, // Directory where user cache can be written. + DIR_APP_LOGS, // Directory where app logs live #if defined(OS_LINUX) DIR_APP_DATA, // Application Data directory under the user profile. diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index d6336962fef6..e5406e519a67 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -4,6 +4,13 @@ #include "brightray/browser/browser_main_parts.h" +#if defined(OSX_POSIX) +#include +#endif + +#include +#include + #include "base/command_line.h" #include "base/feature_list.h" #include "base/strings/string_number_conversions.h" @@ -11,6 +18,7 @@ #include "brightray/browser/browser_context.h" #include "brightray/browser/devtools_manager_delegate.h" #include "brightray/browser/web_ui_controller_factory.h" +#include "brightray/common/application_info.h" #include "brightray/common/main_delegate.h" #include "content/public/browser/browser_thread.h" #include "content/public/common/content_switches.h" @@ -156,11 +164,26 @@ BrowserMainParts::BrowserMainParts() { BrowserMainParts::~BrowserMainParts() { } +#if defined(OS_WIN) || defined(OS_LINUX) +void OverrideAppLogsPath() { +#if defined(OS_WIN) + std::wstring app_name = base::UTF8ToWide(GetApplicationName()); + std::wstring log_path = L"%HOMEDRIVE%%HOMEPATH%\\AppData\\Roaming\\"; + std::wstring app_log_path = log_path + app_name + L"\\logs"; +#else + std::string app_name = GetApplicationName(); + std::string home_path = std::string(getenv("HOME")); + std::string app_log_path = home_path + "/.config/" + app_name + "/logs"; +#endif + PathService::Override(DIR_APP_LOGS, base::FilePath(app_log_path)); +} +#endif + void BrowserMainParts::PreEarlyInitialization() { std::unique_ptr feature_list(new base::FeatureList); feature_list->InitializeFromCommandLine("", ""); base::FeatureList::SetInstance(std::move(feature_list)); - + OverrideAppLogsPath(); #if defined(USE_X11) views::LinuxUI::SetInstance(BuildGtkUi()); OverrideLinuxAppDataPath(); diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index d495e67b5ffa..45c69f15fb07 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -9,6 +9,8 @@ #include "base/compiler_specific.h" #include "base/macros.h" +#include "base/path_service.h" +#include "brightray/browser/brightray_paths.h" #include "content/public/browser/browser_main_parts.h" #include "ui/views/layout/layout_provider.h" @@ -45,6 +47,7 @@ class BrowserMainParts : public content::BrowserMainParts { private: #if defined(OS_MACOSX) void InitializeMainNib(); + void OverrideAppLogsPath(); #endif #if defined(TOOLKIT_VIEWS) diff --git a/brightray/browser/browser_main_parts_mac.mm b/brightray/browser/browser_main_parts_mac.mm index 5e80eca442be..ebcb48ed6461 100644 --- a/brightray/browser/browser_main_parts_mac.mm +++ b/brightray/browser/browser_main_parts_mac.mm @@ -6,6 +6,16 @@ namespace brightray { +void BrowserMainParts::OverrideAppLogsPath() { + base::FilePath path; + NSString* bundleName = [[[NSBundle mainBundle] infoDictionary] + objectForKey:@"CFBundleName"]; + NSString* logsPath = [NSString stringWithFormat:@"Library/Logs/%@",bundleName]; + NSString* libraryPath = [NSHomeDirectory() stringByAppendingPathComponent:logsPath]; + + PathService::Override(DIR_APP_LOGS, base::FilePath([libraryPath UTF8String])); +} + // Replicates NSApplicationMain, but doesn't start a run loop. void BrowserMainParts::InitializeMainNib() { auto infoDictionary = base::mac::OuterBundle().infoDictionary; diff --git a/docs/api/app.md b/docs/api/app.md index b3f4126c9763..6c8bdd1be8c5 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -458,6 +458,7 @@ You can request the following paths by the name: * `music` Directory for a user's music. * `pictures` Directory for a user's pictures. * `videos` Directory for a user's videos. +* `logs` Directory for your app's log folder. * `pepperFlashSystemPlugin` Full path to the system version of the Pepper Flash plugin. ### `app.getFileIcon(path[, options], callback)`