Skip to content

Commit 2a1b7d6

Browse files
committed
fix: use prefix even if custom location is same as home location
1 parent 0e086e1 commit 2a1b7d6

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,10 @@ describe('CliRepl', function () {
14481448
);
14491449
});
14501450

1451-
it('does not use a prefix if the custom location is the same as the home location', async function () {
1451+
it('uses a prefix even if the custom location is the same as the home location', async function () {
1452+
// This is a corner case where the custom location is the same as the home location.
1453+
// The prefix is still added to the log file name for consistency. If the user needs
1454+
// the default behavior for the log names, they should instead set the location to undefined.
14521455
const customLogHomePath = cliRepl.shellHomeDirectory.localPath('.');
14531456
cliRepl.config.logLocation = customLogHomePath;
14541457
await cliRepl.start(await testServer.connectionString(), {});

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,11 @@ 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;
258+
const customLogLocation = await this.getConfig('logLocation');
260259

261260
this.logManager ??= new MongoLogManager({
262-
directory,
263-
prefix: directory !== defaultDirectory ? 'mongosh_' : undefined,
261+
directory: customLogLocation || this.shellHomeDirectory.localPath('.'),
262+
prefix: customLogLocation ? 'mongosh_' : undefined,
264263
retentionDays: await this.getConfig('logRetentionDays'),
265264
gzip: await this.getConfig('logCompressionEnabled'),
266265
maxLogFileCount: await this.getConfig('logMaxFileCount'),

0 commit comments

Comments
 (0)