Skip to content

Commit 73ad25a

Browse files
committed
feat(cli-repl): add option to disable logging
1 parent 42bf834 commit 73ad25a

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,13 @@ describe('CliRepl', function () {
15191519
expect(totalEventsTracked).to.equal(4);
15201520
});
15211521

1522+
it('uses the disable logging setting', function () {
1523+
cliReplOptions.disableLogging = true;
1524+
cliRepl = new CliRepl(cliReplOptions);
1525+
1526+
expect(cliRepl.logWriter?.isDisabled).equals(true);
1527+
});
1528+
15221529
it('sends out telemetry data for command line scripts', async function () {
15231530
cliReplOptions.shellCliOptions.eval = ['db.hello()'];
15241531
cliRepl = new CliRepl(cliReplOptions);

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ export type CliReplOptions = {
9797
onExit: (code?: number) => never;
9898
/** Optional analytics override options. */
9999
analyticsOptions?: AnalyticsOptions;
100+
/** Disables writing logs. */
101+
disableLogging?: boolean;
100102
} & Pick<MongoshNodeReplOptions, 'nodeReplOptions'>;
101103

102104
/** The set of config options that is *always* available in config files stored on the file system. */
@@ -309,7 +311,9 @@ export class CliRepl implements MongoshIOProvider {
309311

310312
await this.logManager.cleanupOldLogFiles();
311313
markTime(TimingCategories.Logging, 'cleaned up log files');
312-
const logger = await this.logManager.createLogWriter();
314+
const logger = await this.logManager.createLogWriter({
315+
isDisabled: this.cliOptions.disableLogging,
316+
});
313317
const { quiet } = CliRepl.getFileAndEvalInfo(this.cliOptions);
314318
if (!quiet) {
315319
this.output.write(`Current Mongosh Log ID:\t${logger.logId}\n`);

packages/logging/src/setup-logger-and-telemetry.spec.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { EventEmitter } from 'events';
66
import { MongoshInvalidInputError } from '@mongosh/errors';
77
import type { MongoshBus } from '@mongosh/types';
88
import { toSnakeCase } from './setup-logger-and-telemetry';
9+
import type { Writable } from 'stream';
910

1011
describe('toSnakeCase', function () {
1112
const useCases = [
@@ -37,15 +38,19 @@ describe('setupLoggerAndTelemetry', function () {
3738
const userId = '53defe995fa47e6c13102d9d';
3839
const logId = '5fb3c20ee1507e894e5340f3';
3940

40-
const logger = new MongoLogWriter(logId, `/tmp/${logId}_log`, {
41-
write(chunk: string, cb: () => void) {
42-
logOutput.push(JSON.parse(chunk));
43-
cb();
44-
},
45-
end(cb: () => void) {
46-
cb();
47-
},
48-
} as any);
41+
const logger = new MongoLogWriter({
42+
logId,
43+
logFilePath: `/tmp/${logId}_log`,
44+
target: {
45+
write(chunk: string, cb: () => void) {
46+
logOutput.push(JSON.parse(chunk));
47+
cb();
48+
},
49+
end(cb: () => void) {
50+
cb();
51+
},
52+
} as Writable,
53+
});
4954
const analytics = {
5055
identify(info: any) {
5156
analyticsOutput.push(['identify', info]);

0 commit comments

Comments
 (0)