Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add this to hooks.logMethod #1559

Merged
merged 1 commit into from Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) => {}