-
Notifications
You must be signed in to change notification settings - Fork 15.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add ability to access logs in getPath() #10191
Conversation
@@ -55,6 +58,8 @@ | |||
|
|||
namespace brightray { | |||
|
|||
void OverrideMacAppLogsPath(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment about the Mac logs file being somewhere else because of Objective-C implementation.
@@ -89,6 +89,18 @@ void OverrideLinuxAppDataPath() { | |||
PathService::Override(DIR_APP_DATA, path); | |||
} | |||
|
|||
// void OverrideWinAppLogsPath() { | |||
// base::FilePath path; | |||
// // should be in c:\program files\myapp\logs ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what commit are you looking at? that was replaced a while ago haha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow... I just clicked the link in my notifications and went to the diff 😕
weird 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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? |
@@ -108,7 +137,7 @@ int BrowserX11IOErrorHandler(Display* d) { | |||
// Wait for the UI thread (which has a different connection to the X server) | |||
// 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awkward word 😄
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The App::GetPath
API (which calls PathService::Get
) automatically creates the dir so there is no need to create it here.
@@ -55,6 +60,8 @@ | |||
|
|||
namespace brightray { | |||
|
|||
void OverrideMacAppLogsPath(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The OverrideMacAppLogsPath
is probably better to be a member of BrowserMainParts
to make things clearer, you can reference how InitializeMainNib
was done.
@@ -4,13 +4,18 @@ | |||
|
|||
#include "brightray/browser/browser_main_parts.h" | |||
|
|||
#include <stdlib.h> | |||
#include <sys/stat.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This header should be guarded with #if defined(OS_POSIX)
since it is not available on Windows.
@@ -156,11 +163,41 @@ BrowserMainParts::BrowserMainParts() { | |||
BrowserMainParts::~BrowserMainParts() { | |||
} | |||
|
|||
void OverrideWinAppLogsPath() { | |||
int status; | |||
std::string appName = GetApplicationName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should use app_name
to conform the coding style.
@@ -156,11 +163,41 @@ BrowserMainParts::BrowserMainParts() { | |||
BrowserMainParts::~BrowserMainParts() { | |||
} | |||
|
|||
void OverrideWinAppLogsPath() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(id)kCFBundleNameKey
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!