Skip to content

Commit 4d52eca

Browse files
ofrobotsDominicKramer
authored andcommitted
fix(middleware): use winston provided child logger api (#359)
Winston now provides a proper child logger API. Use that instead of of our own approximation. This also changes behavior in that the child loggers have /default/ metadata, but individual logs can override the default. Our implementation was the other way around wherein the it was not possible to override the default. The winston behavior seems intuitively more correct. This is not semver major because the middleware code is marked experimental.
1 parent 3161912 commit 4d52eca

4 files changed

Lines changed: 5 additions & 13 deletions

File tree

handwritten/logging-winston/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
**/node_modules
33
.coverage
44
.nyc_output
5+
.vscode
56
docs/
67
out/
78
build/

handwritten/logging-winston/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,6 @@
8989
"winston": "^3.2.1"
9090
},
9191
"peerDependencies": {
92-
"winston": ">=3.1.0"
92+
"winston": ">=3.2.1"
9393
}
9494
}

handwritten/logging-winston/src/middleware/make-child-logger.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@
1717
import * as winston from 'winston';
1818
import {LOGGING_TRACE_KEY} from '../index';
1919

20-
// TODO: winston2 support.
2120
export function makeChildLogger(logger: winston.Logger, trace: string) {
22-
const childLogger = Object.create(logger, {
23-
write: {
24-
value(info: winston.LogEntry) {
25-
info[LOGGING_TRACE_KEY] = trace;
26-
return logger.write(info);
27-
},
28-
},
29-
});
30-
return childLogger;
21+
return logger.child({[LOGGING_TRACE_KEY]: trace});
3122
}

handwritten/logging-winston/test/middleware/make-child-logger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ describe('makeChildLogger', () => {
5959
assert.strictEqual(trace, FAKE_TRACE);
6060
});
6161

62-
it('should overwrite existing LOGGING_TRACE_KEY value', () => {
62+
it('should not overwrite existing LOGGING_TRACE_KEY value', () => {
6363
const child = makeChildLogger(LOGGER, FAKE_TRACE);
6464
let trace;
6565
// tslint:disable-next-line:no-any
6666
(LOGGER.write as any) = (info: winston.LogEntry) => {
6767
trace = info[LOGGING_TRACE_KEY];
6868
};
6969
child.debug('hello world', {[LOGGING_TRACE_KEY]: 'to-be-clobbered'});
70-
assert.strictEqual(trace, FAKE_TRACE);
70+
assert.notStrictEqual(trace, FAKE_TRACE);
7171
});
7272
});

0 commit comments

Comments
 (0)