add ability to access logs in getPath()#10191
Conversation
|
|
||
| namespace brightray { | ||
|
|
||
| void OverrideMacAppLogsPath(); |
There was a problem hiding this comment.
Add a comment about the Mac logs file being somewhere else because of Objective-C implementation.
|
|
||
| // void OverrideWinAppLogsPath() { | ||
| // base::FilePath path; | ||
| // // should be in c:\program files\myapp\logs ? |
There was a problem hiding this comment.
The logs location should be in %LOCALAPPDATA% or %APPDATA so we don't need admin permissions to write the file
There was a problem hiding this comment.
what commit are you looking at? that was replaced a while ago haha
There was a problem hiding this comment.
Wow... I just clicked the link in my notifications and went to the diff 😕
weird 😆
There was a problem hiding this comment.
should be
void OverrideWinAppLogsPath() {
std::string appName = GetApplicationName();
std::string logPath = "%HOMEDRIVE%%HOMEPATH%\\AppData\\Roaming\\";
std::string appLogPath = logPath + appName + "\\logs";
int status = mkdir(appLogPath.c_str(), S_IRWXU | S_IRGRP | S_IROTH);
PathService::Override(DIR_APP_LOGS, base::FilePath(appLogPath));
}
in the current tree :D
|
Hey @codebytere do you wanna take a shot at adding some docs for this too? |
| // to get the error. We can't call shutdown from this thread without | ||
| // tripping an error. Doing it through a function so that we'll be able | ||
| // to see it in any crash dumps. | ||
| // to see it in any crash dumps.back |
| void OverrideLinuxAppLogsPath() { | ||
| std::string appName = GetApplicationName(); | ||
| std::string homePath = std:string(getenv("HOME")); | ||
| std::string appLogPath = homePath + "/.config/" + appName + "/logs"; |
There was a problem hiding this comment.
We're gonna get users asking this to respect $XDG_CONFIG_HOME , current paths don't though (and there is an issue for it). So do what you will 😆
|
Sorry for not getting to this earlier, @codebytere. Would you mind rebasing with master and pushing the changes up to see if we can get CI passing? |
331b2eb to
a71f1fd
Compare
4a8e0ad to
f8b45a1
Compare
|
@codebytere I rebased with master (again) and am seeing this error on CircleCI: |
|
@zcbenz does this look good to you? |
75f37a2 to
0dfadf7
Compare
| std::string logPath = "%HOMEDRIVE%%HOMEPATH%\\AppData\\Roaming\\"; | ||
| std::string appLogPath = logPath + appName + "\\logs"; | ||
|
|
||
| status = mkdir(appLogPath.c_str(), S_IRWXU | S_IRGRP | S_IROTH); |
There was a problem hiding this comment.
The App::GetPath API (which calls PathService::Get) automatically creates the dir so there is no need to create it here.
|
|
||
| namespace brightray { | ||
|
|
||
| void OverrideMacAppLogsPath(); |
There was a problem hiding this comment.
The OverrideMacAppLogsPath is probably better to be a member of BrowserMainParts to make things clearer, you can reference how InitializeMainNib was done.
| #include "brightray/browser/browser_main_parts.h" | ||
|
|
||
| #include <stdlib.h> | ||
| #include <sys/stat.h> |
There was a problem hiding this comment.
This header should be guarded with #if defined(OS_POSIX) since it is not available on Windows.
|
|
||
| void OverrideWinAppLogsPath() { | ||
| int status; | ||
| std::string appName = GetApplicationName(); |
There was a problem hiding this comment.
Should use app_name to conform the coding style.
| BrowserMainParts::~BrowserMainParts() { | ||
| } | ||
|
|
||
| void OverrideWinAppLogsPath() { |
There was a problem hiding this comment.
OverrideWinAppLogsPath and OverrideLinuxAppLogsPath are similar enough to be merged into one function, and you can also rename OverrideMacAppLogsPath to the same to make code simpler:
#if defined(OS_WIN) || defined(OS_LINUX)
void OverrideAppLogsPath() {
std::string app_name = GetApplicationName();
#if defined(OS_WIN)
...
std::string app_log_path = ...
#else
...
std::string app_log_path = ...
#endif
PathService::Override(DIR_APP_LOGS, base::FilePath(app_log_path));
}
#endif
void BrowserMainParts::PreEarlyInitialization() {
...
OverrideAppLogsPath();
}| NSString* logsPath = [NSString stringWithFormat:@"Library/Logs/%@",bundleName]; | ||
|
|
||
| NSString* libraryPath = [NSHomeDirectory() stringByAppendingPathComponent:logsPath]; | ||
| std::string libPathString = std::string([libraryPath UTF8String]); |
There was a problem hiding this comment.
base::FilePath accepts StringPiece as input, so the std::string is not needed:
base::FilePath([libraryPath UTF8String])| void BrowserMainParts::OverrideAppLogsPath() { | ||
| base::FilePath path; | ||
| NSString* bundleName = [[[NSBundle mainBundle] infoDictionary] | ||
| objectForKey:@"CFBundleName"]; |
Adds the ability to get logs via
app.getPath('logs'), implementing feature requested in #10118.Nota Bene: Unlike MacOS, Linux & Windows do not create log folders until a log-worthy event happens, so this implementation lets the app developer ensure the directory exists. If anyone has an idea for an alternate way this could be dealt with please let me know!