1 | import { FastifyError } from '@fastify/error'
|
2 | import { RouteGenericInterface } from './route'
|
3 | import { FastifyRequest } from './request'
|
4 | import { FastifyReply } from './reply'
|
5 | import { RawServerBase, RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, ContextConfigDefault } from './utils'
|
6 | import { FastifyTypeProvider, FastifyTypeProviderDefault } from './type-provider'
|
7 | import { FastifySchema } from './schema'
|
8 | import { FastifyInstance } from './instance'
|
9 |
|
10 | import pino from 'pino'
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | export type FastifyLogFn = pino.LogFn
|
16 |
|
17 | export type LogLevel = pino.LevelWithSilent
|
18 |
|
19 | export type Bindings = pino.Bindings
|
20 |
|
21 | export type ChildLoggerOptions = pino.ChildLoggerOptions
|
22 |
|
23 | export interface FastifyBaseLogger extends pino.BaseLogger {
|
24 | child(bindings: Bindings, options?: ChildLoggerOptions): FastifyBaseLogger
|
25 | }
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | export type FastifyLoggerInstance = FastifyBaseLogger
|
32 |
|
33 | export interface FastifyLoggerStreamDestination {
|
34 | write(msg: string): void;
|
35 | }
|
36 |
|
37 | export type PinoLoggerOptions = pino.LoggerOptions
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | export type ResSerializerReply<
|
44 | RawServer extends RawServerBase,
|
45 | RawReply extends FastifyReply<RawServer>
|
46 | > = Partial<RawReply> & Pick<RawReply, 'statusCode'>;
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | export interface FastifyLoggerOptions<
|
52 | RawServer extends RawServerBase = RawServerDefault,
|
53 | RawRequest extends FastifyRequest<RouteGenericInterface, RawServer, RawRequestDefaultExpression<RawServer>, FastifySchema, FastifyTypeProvider> = FastifyRequest<RouteGenericInterface, RawServer, RawRequestDefaultExpression<RawServer>, FastifySchema, FastifyTypeProviderDefault>,
|
54 | RawReply extends FastifyReply<RawServer, RawRequestDefaultExpression<RawServer>, RawReplyDefaultExpression<RawServer>, RouteGenericInterface, ContextConfigDefault, FastifySchema, FastifyTypeProvider> = FastifyReply<RawServer, RawRequestDefaultExpression<RawServer>, RawReplyDefaultExpression<RawServer>, RouteGenericInterface, ContextConfigDefault, FastifySchema, FastifyTypeProviderDefault>,
|
55 | > {
|
56 | serializers?: {
|
57 | req?: (req: RawRequest) => {
|
58 | method?: string;
|
59 | url?: string;
|
60 | version?: string;
|
61 | hostname?: string;
|
62 | remoteAddress?: string;
|
63 | remotePort?: number;
|
64 | [key: string]: unknown;
|
65 | };
|
66 | err?: (err: FastifyError) => {
|
67 | type: string;
|
68 | message: string;
|
69 | stack: string;
|
70 | [key: string]: unknown;
|
71 | };
|
72 | res?: (res: ResSerializerReply<RawServer, RawReply>) => {
|
73 | statusCode?: string | number;
|
74 | [key: string]: unknown;
|
75 | };
|
76 | };
|
77 | level?: string;
|
78 | file?: string;
|
79 | genReqId?: (req: RawRequest) => string;
|
80 | stream?: FastifyLoggerStreamDestination;
|
81 | }
|
82 |
|
83 | export interface FastifyChildLoggerFactory<
|
84 | RawServer extends RawServerBase = RawServerDefault,
|
85 | RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
|
86 | RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
|
87 | Logger extends FastifyBaseLogger = FastifyBaseLogger,
|
88 | TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault
|
89 | > {
|
90 | |
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | (
|
99 | this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
|
100 | logger: Logger,
|
101 | bindings: Bindings,
|
102 | childLoggerOpts: ChildLoggerOptions,
|
103 | rawReq: RawRequest
|
104 | ): Logger
|
105 | }
|