Skip to content

Commit

Permalink
fix: add this to hooks.logMethod (#1559)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Sep 16, 2022
1 parent 44fe7d1 commit a769539
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pino.d.ts
Expand Up @@ -600,7 +600,7 @@ declare namespace pino {
* log method and method is the log method itself, and level is the log level. This hook must invoke the method function by
* using apply, like so: method.apply(this, newArgumentsArray).
*/
logMethod?: (args: any[], method: LogFn, level: number) => void;
logMethod?: (this: Logger, args: any[], method: LogFn, level: number) => void;
};

/**
Expand Down
5 changes: 3 additions & 2 deletions test/types/pino.test-d.ts
@@ -1,7 +1,7 @@
import P, { pino } from "../../";
import { IncomingMessage, ServerResponse } from "http";
import { Socket } from "net";
import { expectError } from 'tsd'
import { expectError, expectType } from 'tsd'
import Logger = P.Logger;

const log = pino();
Expand Down Expand Up @@ -229,6 +229,7 @@ const withNestedKey = pino({
const withHooks = pino({
hooks: {
logMethod(args, method, level) {
expectType<pino.Logger>(this);
return method.apply(this, ['msg', ...args]);
},
},
Expand Down Expand Up @@ -344,4 +345,4 @@ cclog3.childLevel2('')
const withChildCallback = pino({
onChild: (child: Logger) => {}
})
withChildCallback.onChild = (child: Logger) => {}
withChildCallback.onChild = (child: Logger) => {}

0 comments on commit a769539

Please sign in to comment.