Skip to content

Commit d785677

Browse files
PR requested changes 3 (remaining changes)
1 parent 566dd00 commit d785677

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

src/mongo_logger.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,9 @@ export function stringifyWithMaxLen(
421421
strToTruncate =
422422
typeof value !== 'function'
423423
? EJSON.stringify(value, options)
424-
: value.name !== ''
425-
? value.name
426-
: 'anonymous function';
424+
: 'ReadPreference function';
427425
} catch (e) {
428-
strToTruncate = `... ESJON failed : Error ${e.message}`;
426+
strToTruncate = `Extended JSON serialization failed with: ${e.message}`;
429427
}
430428

431429
return maxDocumentLength !== 0 && strToTruncate.length > maxDocumentLength
@@ -463,7 +461,7 @@ function attachCommandFields(
463461
log.commandName = commandEvent.commandName;
464462
log.requestId = commandEvent.requestId;
465463
log.driverConnectionId = commandEvent.connectionId;
466-
const { host, port } = HostAddress.fromString(commandEvent.address ?? '').toHostPort();
464+
const { host, port } = HostAddress.fromString(commandEvent.address).toHostPort();
467465
log.serverHost = host;
468466
log.serverPort = port;
469467
if (commandEvent?.serviceId) {
@@ -476,7 +474,7 @@ function attachCommandFields(
476474
}
477475

478476
function attachConnectionFields(log: Record<string, any>, event: any) {
479-
const { host, port } = HostAddress.fromString(event.address ?? '').toHostPort();
477+
const { host, port } = HostAddress.fromString(event.address).toHostPort();
480478
log.serverHost = host;
481479
log.serverPort = port;
482480

@@ -498,7 +496,7 @@ function attachServerHeartbeatFields(
498496
const { awaited, connectionId } = serverHeartbeatEvent;
499497
log.awaited = awaited;
500498
log.driverConnectionId = serverHeartbeatEvent.connectionId;
501-
const { host, port } = HostAddress.fromString(connectionId ?? '').toHostPort();
499+
const { host, port } = HostAddress.fromString(connectionId).toHostPort();
502500
log.serverHost = host;
503501
log.serverPort = port;
504502
return log;

test/unit/mongo_logger.test.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
CONNECTION_READY,
2222
createStdioLogger,
2323
DEFAULT_MAX_DOCUMENT_LENGTH,
24-
defaultLogTransform,
2524
type Log,
2625
type MongoDBLogWritable,
2726
MongoLogger,
@@ -57,7 +56,7 @@ describe('meta tests for BufferingStream', function () {
5756
});
5857
});
5958

60-
describe('class MongoLogger', async function () {
59+
describe.only('class MongoLogger', async function () {
6160
describe('#constructor()', function () {
6261
it('assigns each property from the options object onto the logging class', function () {
6362
const componentSeverities: MongoLoggerOptions['componentSeverities'] = {
@@ -1334,15 +1333,6 @@ describe('class MongoLogger', async function () {
13341333
});
13351334
});
13361335

1337-
describe('defaultLogTransform', function () {
1338-
context('when provided a Loggable Event with invalid host-port', function () {
1339-
// this is an important case to consider, because in the case of an undefined address, the HostAddress.toString() function will throw
1340-
it('should not throw and output empty host string instead', function () {
1341-
expect(defaultLogTransform({ name: 'connectionCreated' }).serverHost).to.equal('');
1342-
});
1343-
});
1344-
});
1345-
13461336
describe('log', async function () {
13471337
const componentSeverities: MongoLoggerOptions['componentSeverities'] = {
13481338
command: 'trace',

0 commit comments

Comments
 (0)