Skip to content

Commit 275b7ad

Browse files
committed
refactor: move custom log entries into new structure
1 parent 214ca17 commit 275b7ad

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,7 @@ describe('e2e', function () {
13631363
let logBasePath: string;
13641364
let historyPath: string;
13651365
let readConfig: () => Promise<any>;
1366-
let readLogFile: () => Promise<LogEntry[]>;
1366+
let readLogFile: <T = LogEntry>() => Promise<T[]>;
13671367
let startTestShell: (...extraArgs: string[]) => Promise<TestShell>;
13681368

13691369
beforeEach(function () {
@@ -1659,7 +1659,12 @@ describe('e2e', function () {
16591659
await shell.executeLine("log.info('This is a custom entry')");
16601660
expect(shell.assertNoErrors());
16611661
await eventually(async () => {
1662-
const log = await readLogfile();
1662+
const log = await readLogFile<{
1663+
msg: string;
1664+
s: string;
1665+
c: string;
1666+
ctx: string;
1667+
}>();
16631668
const customLogEntry = log.filter((logEntry) =>
16641669
logEntry.msg.includes('This is a custom entry')
16651670
);
@@ -1683,7 +1688,7 @@ describe('e2e', function () {
16831688
await shell.executeLine(`load(${JSON.stringify(filename)})`);
16841689
expect(shell.assertNoErrors());
16851690
await eventually(async () => {
1686-
const log = await readLogfile();
1691+
const log = await readLogFile<{ msg: string }>();
16871692
expect(
16881693
log.filter((logEntry) =>
16891694
logEntry.msg.includes('Initiating connection attemp')

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -941,19 +941,12 @@ describe('MongoshLoggingAndTelemetry', function () {
941941
});
942942

943943
it('tracks custom logging events', function () {
944-
setupLoggerAndTelemetry(
945-
bus,
946-
logger,
947-
analytics,
948-
{
949-
platform: process.platform,
950-
arch: process.arch,
951-
},
952-
'1.0.0'
953-
);
954944
expect(logOutput).to.have.lengthOf(0);
955945
expect(analyticsOutput).to.be.empty;
956946

947+
loggingAndTelemetry.setup();
948+
loggingAndTelemetry.attachLogger(logger);
949+
957950
bus.emit('mongosh:connect', {
958951
uri: 'mongodb://localhost/',
959952
is_localhost: true,

packages/logging/src/logging-and-telemetry.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import type {
3232
FetchingUpdateMetadataCompleteEvent,
3333
SessionStartedEvent,
3434
MongoshBusEventsMap,
35+
WriteCustomLogEvent,
3536
} from '@mongosh/types';
3637
import { inspect } from 'util';
3738
import { MongoLogWriter } from 'mongodb-log-writer';
@@ -320,6 +321,19 @@ export class MongoshLoggingAndTelemetry {
320321
}
321322
});
322323

324+
onBus('mongosh:write-custom-log', (event: WriteCustomLogEvent) => {
325+
if (this.log) {
326+
this.log[event.method](
327+
'MONGOSH-SCRIPTS',
328+
mongoLogId(1_000_000_054),
329+
'custom-log',
330+
event.message,
331+
event.attr,
332+
event.level
333+
);
334+
}
335+
});
336+
323337
onBus('mongosh:globalconfig-load', (args: GlobalConfigFileLoadEvent) => {
324338
this.log?.info(
325339
'MONGOSH',

packages/types/src/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,6 @@ export interface MongocryptdLogEvent {
9797
logEntry: any;
9898
}
9999

100-
export interface WriteCustomLogEvent {
101-
method: 'info' | 'error' | 'warn' | 'debug';
102-
message: string;
103-
attr?: unknown;
104-
level?: 1 | 2 | 3 | 4 | 5;
105-
}
106-
107100
export interface StartMongoshReplEvent {
108101
version: string;
109102
}

0 commit comments

Comments
 (0)