Skip to content

Commit 263d285

Browse files
committed
feat(logging): add max file count configuration MONGOSH-1987
1 parent b27afb7 commit 263d285

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

packages/cli-repl/src/cli-repl.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ describe('CliRepl', function () {
324324
'disableLogging',
325325
'logLocation',
326326
'logRetentionDays',
327+
'logMaxFileCount',
327328
] satisfies (keyof CliUserConfig)[]);
328329
});
329330

@@ -1450,6 +1451,19 @@ describe('CliRepl', function () {
14501451
testRetentionDays
14511452
);
14521453
});
1454+
1455+
it('can set log max file count', async function () {
1456+
const testMaxFileCount = 123;
1457+
cliRepl.config.logMaxFileCount = testMaxFileCount;
1458+
await cliRepl.start(await testServer.connectionString(), {});
1459+
1460+
expect(cliRepl.getConfig('logMaxFileCount')).equals(
1461+
testMaxFileCount
1462+
);
1463+
expect(cliRepl.logManager?._options.maxLogFileCount).equals(
1464+
testMaxFileCount
1465+
);
1466+
});
14531467
});
14541468

14551469
it('times out fast', async function () {

packages/cli-repl/src/cli-repl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ export class CliRepl implements MongoshIOProvider {
261261
this.shellHomeDirectory.localPath('.'),
262262
retentionDays: await this.getConfig('logRetentionDays'),
263263
maxLogFileCount: +(
264-
process.env.MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT || 100
264+
process.env.MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT ||
265+
(await this.getConfig('logMaxFileCount'))
265266
),
266267
onerror: (err: Error) => this.bus.emit('mongosh:error', err, 'log'),
267268
onwarn: (err: Error, path: string) =>

packages/types/src/index.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ describe('config validation', function () {
3131
expect(await validate('logRetentionDays', -1)).to.equal(
3232
'logRetentionDays must be a positive integer'
3333
);
34+
expect(await validate('logMaxFileCount', 'foo')).to.equal(
35+
'logMaxFileCount must be a positive integer'
36+
);
37+
expect(await validate('logMaxFileCount', -1)).to.equal(
38+
'logMaxFileCount must be a positive integer'
39+
);
3440
expect(await validate('showStackTraces', 'foo')).to.equal(
3541
'showStackTraces must be a boolean'
3642
);

packages/types/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ export class CliUserConfig extends SnippetShellUserConfig {
510510
disableLogging = false;
511511
logLocation: string | undefined = undefined;
512512
logRetentionDays = 30;
513+
logMaxFileCount = 100;
513514
}
514515

515516
export class CliUserConfigValidator extends SnippetShellUserConfigValidator {
@@ -533,6 +534,7 @@ export class CliUserConfigValidator extends SnippetShellUserConfigValidator {
533534
case 'inspectDepth':
534535
case 'historyLength':
535536
case 'logRetentionDays':
537+
case 'logMaxFileCount':
536538
if (typeof value !== 'number' || value < 0) {
537539
return `${key} must be a positive integer`;
538540
}

0 commit comments

Comments
 (0)