Skip to content

Commit

Permalink
feat(logging): add max file count configuration MONGOSH-1987
Browse files Browse the repository at this point in the history
  • Loading branch information
gagik committed Feb 4, 2025
1 parent 654b1ec commit 166f82e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
14 changes: 14 additions & 0 deletions packages/cli-repl/src/cli-repl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ describe('CliRepl', function () {
'disableLogging',
'logLocation',
'logRetentionDays',
'logMaxFileCount',
] satisfies (keyof CliUserConfig)[]);
});

Expand Down Expand Up @@ -1434,6 +1435,19 @@ describe('CliRepl', function () {
testRetentionDays
);
});

it('can set log max file count', async function () {
const testMaxFileCount = 123;
cliRepl.config.logMaxFileCount = testMaxFileCount;
await cliRepl.start(await testServer.connectionString(), {});

expect(cliRepl.getConfig('logMaxFileCount')).equals(
testMaxFileCount
);
expect(cliRepl.logManager?._options.maxLogFileCount).equals(
testMaxFileCount
);
});
});

it('times out fast', async function () {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli-repl/src/cli-repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ export class CliRepl implements MongoshIOProvider {
this.shellHomeDirectory.localPath('.'),
retentionDays: await this.getConfig('logRetentionDays'),
maxLogFileCount: +(
process.env.MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT || 100
process.env.MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT ||
(await this.getConfig('logMaxFileCount'))
),
onerror: (err: Error) => this.bus.emit('mongosh:error', err, 'log'),
onwarn: (err: Error, path: string) =>
Expand Down
6 changes: 6 additions & 0 deletions packages/types/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ describe('config validation', function () {
expect(await validate('logRetentionDays', -1)).to.equal(
'logRetentionDays must be a positive integer'
);
expect(await validate('logMaxFileCount', 'foo')).to.equal(
'logMaxFileCount must be a positive integer'
);
expect(await validate('logMaxFileCount', -1)).to.equal(
'logMaxFileCount must be a positive integer'
);
expect(await validate('showStackTraces', 'foo')).to.equal(
'showStackTraces must be a boolean'
);
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ export class CliUserConfig extends SnippetShellUserConfig {
disableLogging = false;
logLocation: string | undefined = undefined;
logRetentionDays = 30;
logMaxFileCount = 100;
}

export class CliUserConfigValidator extends SnippetShellUserConfigValidator {
Expand All @@ -533,6 +534,7 @@ export class CliUserConfigValidator extends SnippetShellUserConfigValidator {
case 'inspectDepth':
case 'historyLength':
case 'logRetentionDays':
case 'logMaxFileCount':
if (typeof value !== 'number' || value < 0) {
return `${key} must be a positive integer`;
}
Expand Down

0 comments on commit 166f82e

Please sign in to comment.