UNPKG

2.04 kBTypeScriptView Raw
1import { FastifyError } from 'fastify-error'
2import { RawServerBase, RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression } from './utils'
3import { FastifyRequest, RequestGenericInterface } from './request'
4
5/**
6 * Standard Fastify logging function
7 */
8export interface FastifyLogFn {
9 (msg: string, ...args: unknown[]): void;
10 (obj: object, msg?: string, ...args: unknown[]): void;
11}
12
13export type LogLevel = 'info' | 'error' | 'debug' | 'fatal' | 'warn' | 'trace'
14
15export type SerializerFn = (value: unknown) => unknown;
16
17export interface Bindings {
18 level?: LogLevel | string;
19 serializers?: { [key: string]: SerializerFn };
20 [key: string]: unknown;
21}
22
23export interface FastifyLoggerInstance {
24 info: FastifyLogFn;
25 warn: FastifyLogFn;
26 error: FastifyLogFn;
27 fatal: FastifyLogFn;
28 trace: FastifyLogFn;
29 debug: FastifyLogFn;
30 child(bindings: Bindings): FastifyLoggerInstance;
31}
32
33/**
34 * Fastify Custom Logger options. To enable configuration of all Pino options,
35 * refer to this example:
36 * https://github.com/fastify/fastify/blob/2f56e10a24ecb70c2c7950bfffd60eda8f7782a6/docs/TypeScript.md#example-5-specifying-logger-types
37 */
38export interface FastifyLoggerOptions<
39 RawServer extends RawServerBase = RawServerDefault,
40 RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
41 RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>
42> {
43 serializers?: {
44 req: (req: RawRequest) => {
45 method: string;
46 url: string;
47 version: string;
48 hostname: string;
49 remoteAddress: string;
50 remotePort: number;
51 };
52 err: (err: FastifyError) => {
53 type: string;
54 message: string;
55 stack: string;
56 [key: string]: any;
57 };
58 res: (res: RawReply) => {
59 statusCode: string | number;
60 };
61 };
62 level?: string;
63 genReqId?: <RequestGeneric extends RequestGenericInterface = RequestGenericInterface>(req: FastifyRequest<RequestGeneric, RawServer, RawRequest>) => string;
64}