Skip to content

Commit 4cde442

Browse files
committed
feat(logging): add max file count configuration MONGOSH-1987
1 parent 943b065 commit 4cde442

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

@@ -1457,6 +1458,19 @@ describe('CliRepl', function () {
14571458
testRetentionDays
14581459
);
14591460
});
1461+
1462+
it('can set log max file count', async function () {
1463+
const testMaxFileCount = 123;
1464+
cliRepl.config.logMaxFileCount = testMaxFileCount;
1465+
await cliRepl.start(await testServer.connectionString(), {});
1466+
1467+
expect(cliRepl.getConfig('logMaxFileCount')).equals(
1468+
testMaxFileCount
1469+
);
1470+
expect(cliRepl.logManager?._options.maxLogFileCount).equals(
1471+
testMaxFileCount
1472+
);
1473+
});
14601474
});
14611475

14621476
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)