Skip to content

Commit 2b95ea9

Browse files
committed
feat(cli-repl): use mongosh_ prefix for logs in custom locations
1 parent 33f85ff commit 2b95ea9

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ describe('CliRepl', function () {
14321432
});
14331433

14341434
const customLogLocation = useTmpdir();
1435-
it('can set the log location', async function () {
1435+
it('can set the log location and uses a prefix', async function () {
14361436
cliRepl.config.logLocation = customLogLocation.path;
14371437
await cliRepl.start(await testServer.connectionString(), {});
14381438

@@ -1442,6 +1442,22 @@ describe('CliRepl', function () {
14421442
expect(cliRepl.logWriter?.logFilePath).equals(
14431443
path.join(
14441444
customLogLocation.path,
1445+
'mongosh_' + (cliRepl.logWriter?.logId as string) + '_log'
1446+
)
1447+
);
1448+
});
1449+
1450+
it('does not use a prefix if the custom location is the same as the home location', async function () {
1451+
const customLogHomePath = cliRepl.shellHomeDirectory.localPath('.');
1452+
cliRepl.config.logLocation = customLogHomePath;
1453+
await cliRepl.start(await testServer.connectionString(), {});
1454+
1455+
expect(await cliRepl.getConfig('logLocation')).equals(
1456+
customLogHomePath
1457+
);
1458+
expect(cliRepl.logWriter?.logFilePath).equals(
1459+
path.join(
1460+
customLogHomePath,
14451461
(cliRepl.logWriter?.logId as string) + '_log'
14461462
)
14471463
);

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,12 @@ export class CliRepl implements MongoshIOProvider {
255255
throw new Error('Logging and telemetry not setup');
256256
}
257257

258+
const defaultDirectory = this.shellHomeDirectory.localPath('.');
259+
const directory = (await this.getConfig('logLocation')) || defaultDirectory;
260+
258261
this.logManager ??= new MongoLogManager({
259-
directory:
260-
(await this.getConfig('logLocation')) ||
261-
this.shellHomeDirectory.localPath('.'),
262+
directory,
263+
prefix: directory !== defaultDirectory ? 'mongosh_' : undefined,
262264
retentionDays: await this.getConfig('logRetentionDays'),
263265
gzip: await this.getConfig('logCompressionEnabled'),
264266
maxLogFileCount: +(

packages/e2e-tests/test/e2e.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,7 @@ describe('e2e', function () {
14071407
}
14081408
const logPath = path.join(
14091409
customBasePath ?? logBasePath,
1410-
`${shell.logId}_log`
1410+
`${customBasePath ? 'mongosh_' : ''}${shell.logId}_log`
14111411
);
14121412
return readReplLogFile<T>(logPath);
14131413
};

0 commit comments

Comments
 (0)