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

feat(cli-repl): add ability to set log location MONGOSH-1983 #2326

Draft
wants to merge 4 commits into
base: gagik/add-disable-logging
Choose a base branch
from

Conversation

gagik
Copy link
Contributor

@gagik gagik commented Jan 22, 2025

Adds ability to configure log location.

@gagik gagik marked this pull request as draft January 22, 2025 15:19
@gagik gagik changed the title feat(mongodb-log-writer): add ability to set log location MONGOSH-1983 WIP feat(mongodb-log-writer): add ability to set log location MONGOSH-1983 Jan 22, 2025
@gagik gagik force-pushed the gagik/add-log-location branch from 10cb29c to 718990c Compare January 22, 2025 15:37
@gagik gagik force-pushed the gagik/add-disable-logging branch 6 times, most recently from 3b38cc7 to ef79cf4 Compare January 24, 2025 16:44
gagik added 3 commits January 26, 2025 23:00
…initialization

I think this refactor provides much better readability and provides an easier interface for us to test and debug the functionality of this. This also moves the hookLoggers call to the point of initialization as
Adds validation for the disableLogging field and fixes the equivalent test.
@gagik gagik force-pushed the gagik/add-disable-logging branch from 054080c to 5147039 Compare January 26, 2025 22:00
@gagik gagik force-pushed the gagik/add-log-location branch 4 times, most recently from 3060ce3 to fa404ed Compare January 27, 2025 08:58
@gagik gagik changed the title WIP feat(mongodb-log-writer): add ability to set log location MONGOSH-1983 feat(cli-repl): add ability to set log location MONGOSH-1983 Jan 27, 2025
@gagik gagik force-pushed the gagik/add-log-location branch from fa404ed to b17d60c Compare January 27, 2025 09:15
@@ -574,6 +575,11 @@ export class CliUserConfigValidator extends SnippetShellUserConfigValidator {
return `${key} must be a valid URL or empty`;
}
return null;
case 'logLocation':
if (value !== undefined && typeof value !== 'string') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if there's a good way to check for valid path. I was thinking regex but worried it'd be end up disallowing valid paths in weirder OSes. Running fs.access could be a way, just seems to be a bit more proactive validator than others.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path.isAbsolute()? Allowing a relative path seems like a great way to cause chaos, if we do that, we should also specify a relatively fixed path that it is relative to (e.g. os.homedir()).

@gagik gagik marked this pull request as ready for review January 27, 2025 09:15
@gagik gagik requested a review from alenakhineika January 27, 2025 09:15
Copy link
Contributor

@addaleax addaleax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should come with an e2e test that verifies that the file actually gets created and written to (in this section:

describe('config, logging and rc file', function () {
).

@@ -190,7 +190,8 @@ export class CliRepl implements MongoshIOProvider {
});

this.logManager = new MongoLogManager({
directory: this.shellHomeDirectory.localPath('.'),
directory:
this.getConfig('logLocation') ?? this.shellHomeDirectory.localPath('.'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.getConfig() doesn't work yet before the .generateOrReadConfig() and .loadGlobalConfigFile() calls in .start().

@@ -574,6 +575,11 @@ export class CliUserConfigValidator extends SnippetShellUserConfigValidator {
return `${key} must be a valid URL or empty`;
}
return null;
case 'logLocation':
if (value !== undefined && typeof value !== 'string') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path.isAbsolute()? Allowing a relative path seems like a great way to cause chaos, if we do that, we should also specify a relatively fixed path that it is relative to (e.g. os.homedir()).

@gagik gagik marked this pull request as draft January 29, 2025 12:57
@gagik gagik force-pushed the gagik/add-disable-logging branch 2 times, most recently from 275b7ad to 214ca17 Compare January 30, 2025 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants