Skip to content

Commit

Permalink
Child log level in bindings is deprecated (#3896)
Browse files Browse the repository at this point in the history
Co-authored-by: Igor Savin <iselwin@gmail.com>
  • Loading branch information
orov-io and kibertoad committed Jun 1, 2022
1 parent e94cd92 commit 68a290d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
14 changes: 13 additions & 1 deletion test/types/logger.test-d.ts
@@ -1,4 +1,4 @@
import { expectType } from 'tsd'
import { expectError, expectType } from 'tsd'
import fastify, { FastifyLogFn, LogLevel, FastifyLoggerInstance, FastifyError, FastifyRequest, FastifyReply } from '../../fastify'
import { Server, IncomingMessage, ServerResponse } from 'http'
import pino from 'pino'
Expand Down Expand Up @@ -183,3 +183,15 @@ const passStreamAsOption = fastify({
stream: fs.createWriteStream('/tmp/stream.out')
}
})

const childParent = fastify().log
// we test different option variant here
expectType<FastifyLoggerInstance>(childParent.child({}, { level: 'info' }))
expectType<FastifyLoggerInstance>(childParent.child({}, { redact: ['pass', 'pin'] }))
expectType<FastifyLoggerInstance>(childParent.child({}, { serializers: { key: () => {} } }))
expectType<FastifyLoggerInstance>(childParent.child({}, { level: 'info', redact: ['pass', 'pin'], serializers: { key: () => {} } }))

// no option pass
expectError(childParent.child())
// wrong option
expectError(childParent.child({}, { nonExist: true }))
13 changes: 12 additions & 1 deletion types/logger.d.ts
Expand Up @@ -36,20 +36,31 @@ export type LogLevel = 'info' | 'error' | 'debug' | 'fatal' | 'warn' | 'trace'

export type SerializerFn = (value: unknown) => unknown;

export interface redactOptions {
paths: string[];
censor?: string | ((v: any) => any) | undefined;
remove?: boolean | undefined;
}
export interface Bindings {
level?: LogLevel | string;
serializers?: { [key: string]: SerializerFn };
[key: string]: unknown;
}

export interface ChildLoggerOptions {
level?: LogLevel | string;
redact?: string[] | redactOptions | undefined;
serializers?: { [key: string]: SerializerFn } | undefined;
}

export interface FastifyLoggerInstance {
info: FastifyLogFn;
warn: FastifyLogFn;
error: FastifyLogFn;
fatal: FastifyLogFn;
trace: FastifyLogFn;
debug: FastifyLogFn;
child(bindings: Bindings): FastifyLoggerInstance;
child(bindings: Bindings, options?: ChildLoggerOptions): FastifyLoggerInstance;
}

// This interface is accurate for pino 6.3 and was copied from the following permalink:
Expand Down

0 comments on commit 68a290d

Please sign in to comment.