Skip to content
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

Merged
merged 17 commits into from Sep 29, 2017
Merged

add ability to access logs in getPath() #10191

merged 17 commits into from Sep 29, 2017

Conversation

@codebytere
Copy link
Member

@codebytere codebytere commented Aug 3, 2017

Adds the ability to get logs via app.getPath('logs'), implementing feature requested in #10118.

  • MacOS
  • Linux
  • Windows

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!

@jkleinsc jkleinsc changed the title add ability to access logs in getPath() [WIP] add ability to access logs in getPath() Aug 7, 2017
@@ -55,6 +58,8 @@

namespace brightray {

void OverrideMacAppLogsPath();

This comment has been minimized.

@groundwater

groundwater Aug 8, 2017
Member

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 ?

This comment has been minimized.

@MarshallOfSound

MarshallOfSound Aug 9, 2017
Member

The logs location should be in %LOCALAPPDATA% or %APPDATA so we don't need admin permissions to write the file

This comment has been minimized.

@codebytere

codebytere Aug 9, 2017
Author Member

what commit are you looking at? that was replaced a while ago haha

This comment has been minimized.

@MarshallOfSound

MarshallOfSound Aug 9, 2017
Member

Wow... I just clicked the link in my notifications and went to the diff 😕

weird 😆

This comment has been minimized.

@codebytere

codebytere Aug 9, 2017
Author Member

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

@zeke
Copy link
Member

@zeke zeke commented Aug 10, 2017

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

This comment has been minimized.

@MarshallOfSound

MarshallOfSound Aug 14, 2017
Member

Awkward word 😄

void OverrideLinuxAppLogsPath() {
std::string appName = GetApplicationName();
std::string homePath = std:string(getenv("HOME"));
std::string appLogPath = homePath + "/.config/" + appName + "/logs";

This comment has been minimized.

@MarshallOfSound

MarshallOfSound Aug 14, 2017
Member

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 😆

@zeke zeke self-assigned this Aug 16, 2017
@zeke
Copy link
Member

@zeke zeke commented Sep 20, 2017

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?

@codebytere codebytere force-pushed the add_log_path_support branch from 331b2eb to a71f1fd Sep 20, 2017
@zeke zeke force-pushed the add_log_path_support branch from 4a8e0ad to f8b45a1 Sep 24, 2017
@zeke
Copy link
Member

@zeke zeke commented Sep 24, 2017

@codebytere I rebased with master (again) and am seeing this error on CircleCI:

../../brightray/browser/browser_main_parts.cc:110:29: error: unexpected ':' in nested name specifier; did you mean '::'?
  std::string homePath = std:string(getenv("HOME"));
@zeke zeke requested a review from zcbenz Sep 28, 2017
@zeke
Copy link
Member

@zeke zeke commented Sep 28, 2017

@zcbenz does this look good to you?

testinterntest and others added 14 commits Aug 3, 2017
@codebytere codebytere force-pushed the add_log_path_support branch from 75f37a2 to 0dfadf7 Sep 28, 2017
@codebytere codebytere requested review from Sep 28, 2017
@codebytere codebytere changed the title [WIP] add ability to access logs in getPath() add ability to access logs in getPath() Sep 29, 2017
std::string logPath = "%HOMEDRIVE%%HOMEPATH%\\AppData\\Roaming\\";
std::string appLogPath = logPath + appName + "\\logs";

status = mkdir(appLogPath.c_str(), S_IRWXU | S_IRGRP | S_IROTH);

This comment has been minimized.

@zcbenz

zcbenz Sep 29, 2017
Member

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();

This comment has been minimized.

@zcbenz

zcbenz Sep 29, 2017
Member

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>

This comment has been minimized.

@zcbenz

zcbenz Sep 29, 2017
Member

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();

This comment has been minimized.

@zcbenz

zcbenz Sep 29, 2017
Member

Should use app_name to conform the coding style.

@@ -156,11 +163,41 @@ BrowserMainParts::BrowserMainParts() {
BrowserMainParts::~BrowserMainParts() {
}

void OverrideWinAppLogsPath() {

This comment has been minimized.

@zcbenz

zcbenz Sep 29, 2017
Member

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]);

This comment has been minimized.

@zcbenz

zcbenz Sep 29, 2017
Member

base::FilePath accepts StringPiece as input, so the std::string is not needed:

base::FilePath([libraryPath UTF8String])
codebytere added 2 commits Sep 29, 2017
@zeke zeke dismissed zcbenz’s stale review Sep 29, 2017

All requested changes were made.

@zeke
zeke approved these changes Sep 29, 2017
@zeke zeke merged commit 9f89587 into master Sep 29, 2017
8 checks passed
8 checks passed
ci/circleci: electron-linux-arm Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-arm64 Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-ia32 Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-x64 Your tests passed on CircleCI!
Details
continuous-integration/appveyor/branch AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
electron-mas-x64 Build #5277 succeeded in 24 min
Details
electron-osx-x64 Build #5261 succeeded in 25 min
Details
@zeke zeke deleted the add_log_path_support branch Sep 29, 2017
void BrowserMainParts::OverrideAppLogsPath() {
base::FilePath path;
NSString* bundleName = [[[NSBundle mainBundle] infoDictionary]
objectForKey:@"CFBundleName"];

This comment has been minimized.

@pronebird

pronebird Sep 30, 2017

(id)kCFBundleNameKey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants
You can’t perform that action at this time.