Skip to content

Commit d06bcbe

Browse files
authored
Handles null in structured logging (Fixes #716) (#717)
1 parent f9b24e0 commit d06bcbe

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

spec/logger.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ describe(`logger (${
6565
});
6666
sandbox.restore(); // to avoid swallowing test runner output
6767
});
68+
69+
it('should not recognize null as a structured logging object', () => {
70+
logger.log('hello', 'world', null);
71+
expectStdout({
72+
severity: 'INFO',
73+
message: 'hello world null',
74+
});
75+
sandbox.restore(); // to avoid swallowing test runner output
76+
});
6877
});
6978

7079
describe('write', () => {

src/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export function error(...args: any[]) {
104104
function entryFromArgs(severity: LogSeverity, args: any[]): LogEntry {
105105
let entry = {};
106106
const lastArg = args[args.length - 1];
107-
if (typeof lastArg == 'object' && lastArg.constructor == Object) {
107+
if (lastArg && typeof lastArg == 'object' && lastArg.constructor == Object) {
108108
entry = args.pop();
109109
}
110110
return Object.assign({}, entry, {

0 commit comments

Comments
 (0)