Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 04fd2c4

Browse files
author
Michal Vlasák
committed
Update pino and typescript packages
1 parent cd35baf commit 04fd2c4

3 files changed

Lines changed: 28 additions & 16 deletions

File tree

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
"dependencies": {
3434
"@types/express": "^4.16.0",
35-
"@types/pino": "^4.16.1",
35+
"@types/pino": "^5.8.10",
3636
"lodash.foreach": "^4.5.0",
3737
"lodash.isempty": "^4.4.0",
3838
"lodash.isobject": "^3.0.2",
@@ -41,8 +41,8 @@
4141
"on-finished": "^2.3.0",
4242
"on-headers": "^1.0.1",
4343
"pick-deep": "^1.0.0",
44-
"pino": "^4.17.6",
45-
"pino-multi-stream": "^3.1.2"
44+
"pino": "^5.13.2",
45+
"pino-multi-stream": "^4.2.0"
4646
},
4747
"devDependencies": {
4848
"@types/jest": "^24.0.13",
@@ -65,7 +65,7 @@
6565
"ts-jest": "^24.0.0",
6666
"tslint": "^5.11.0",
6767
"tslint-config-ackee": "^0.3.0",
68-
"typescript": "^3.3.3333"
68+
"typescript": "^3.5.3"
6969
},
7070
"husky": {
7171
"hooks": {

src/index.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,25 @@ export interface AckeeLoggerFactory extends AckeeLogger {
2525
}
2626

2727
// This is a custom slightly edited version of pino-multistream's write method, which adds support for maximum log level
28-
// The original version was pino-multistream 3.1.2 (commit 71d98ae) - https://github.com/pinojs/pino-multi-stream/blob/71d98ae191e02c56e39e849d2c30d59c8c6db1b9/multistream.js#L43
28+
// The original version was pino-multistream 4.2.0 (commit bf7941f) - https://github.com/pinojs/pino-multi-stream/blob/bf7941f77661b6c14dd40840ff4a4db6897f08eb/multistream.js#L43
2929
const maxLevelWrite: pino.WriteFn = function(this: any, data: object): void {
3030
let stream;
31-
const needsMetadata = Symbol.for('needsMetadata');
31+
const metadata = Symbol.for('pino.metadata');
3232
const level = this.lastLevel;
3333
const streams = this.streams;
3434
for (const dest of streams) {
3535
stream = dest.stream;
3636
// tslint:disable-next-line:early-exit
3737
if (dest.level <= level) {
3838
if (!dest.maxLevel || (dest.maxLevel && level < dest.maxLevel)) {
39-
if (stream[needsMetadata]) {
39+
if (stream[metadata]) {
40+
// tslint:disable-next-line:no-this-assignment
41+
const { lastTime, lastMsg, lastObj, lastLogger } = this;
4042
stream.lastLevel = level;
41-
stream.lastMsg = this.lastMsg;
42-
stream.lastObj = this.lastObj;
43-
stream.lastLogger = this.lastLogger;
43+
stream.lastTime = lastTime;
44+
stream.lastMsg = lastMsg;
45+
stream.lastObj = lastObj;
46+
stream.lastLogger = lastLogger;
4447
}
4548
stream.write(data);
4649
}
@@ -78,8 +81,9 @@ const defaultLogger = (options: AckeeLoggerOptions & { loggerName?: string } = {
7881

7982
// Add maxLevel support to pino-multi-stream
8083
// This could be replaced with custom pass-through stream being passed to multistream, which would filter the messages
81-
const streamMaxLevelWrite = maxLevelWrite.bind(logger.stream);
82-
logger.stream.write = (chunk: any) => {
84+
const loggerStream = (logger as any)[(pino as any).symbols.streamSym] as any;
85+
const streamMaxLevelWrite = maxLevelWrite.bind(loggerStream);
86+
loggerStream.write = (chunk: any) => {
8387
streamMaxLevelWrite(chunk);
8488
return true;
8589
};

src/streams.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,21 @@ const initLoggerStreams = (
5656
if (options.streams) {
5757
streams = options.streams.map(stream => Object.assign({ level: defaultLevel }, stream));
5858
} else if (options.pretty) {
59-
const pretty = pino.pretty();
59+
const pretty = pino({
60+
prettyPrint: {
61+
levelFirst: true,
62+
},
63+
});
6064
pretty.pipe(process.stdout);
61-
const prettyErr = pino.pretty();
65+
const prettyErr = pino({
66+
prettyPrint: {
67+
levelFirst: true,
68+
},
69+
});
6270
prettyErr.pipe(process.stderr);
6371
streams = [
64-
{ level: defaultLevel, maxLevel: levels.warn, stream: pretty },
65-
{ level: 'warn', stream: prettyErr },
72+
{ level: defaultLevel, maxLevel: levels.warn, stream: pretty as any },
73+
{ level: 'warn', stream: prettyErr as any },
6674
];
6775
} else {
6876
streams = [

0 commit comments

Comments
 (0)