forked from fastify/fastify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.d.ts
105 lines (93 loc) · 3.93 KB
/
logger.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { FastifyError } from '@fastify/error'
import { FastifyInstance } from './instance'
import { FastifyReply } from './reply'
import { FastifyRequest } from './request'
import { RouteGenericInterface } from './route'
import { FastifySchema } from './schema'
import { FastifyTypeProvider, FastifyTypeProviderDefault } from './type-provider'
import { ContextConfigDefault, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault } from './utils'
import pino from 'pino'
/**
* Standard Fastify logging function
*/
export type FastifyLogFn = pino.LogFn
export type LogLevel = pino.LevelWithSilent
export type Bindings = pino.Bindings
export type ChildLoggerOptions = pino.ChildLoggerOptions
export interface FastifyBaseLogger extends pino.BaseLogger {
child(bindings: Bindings, options?: ChildLoggerOptions): FastifyBaseLogger
}
// TODO delete FastifyBaseLogger in the next major release. It seems that it is enough to have only FastifyBaseLogger.
/**
* @deprecated Use FastifyBaseLogger instead
*/
export type FastifyLoggerInstance = FastifyBaseLogger
export interface FastifyLoggerStreamDestination {
write(msg: string): void;
}
export type PinoLoggerOptions = pino.LoggerOptions
// TODO: once node 18 is EOL, this type can be replaced with plain FastifyReply.
/**
* Specialized reply type used for the `res` log serializer, since only `statusCode` is passed in certain cases.
*/
export type ResSerializerReply<
RawServer extends RawServerBase,
RawReply extends FastifyReply<RouteGenericInterface, RawServer>
> = Partial<RawReply> & Pick<RawReply, 'statusCode'>
/**
* Fastify Custom Logger options.
*/
export interface FastifyLoggerOptions<
RawServer extends RawServerBase = RawServerDefault,
RawRequest extends FastifyRequest<RouteGenericInterface, RawServer, RawRequestDefaultExpression<RawServer>, FastifySchema, FastifyTypeProvider> = FastifyRequest<RouteGenericInterface, RawServer, RawRequestDefaultExpression<RawServer>, FastifySchema, FastifyTypeProviderDefault>,
RawReply extends FastifyReply<RouteGenericInterface, RawServer, RawRequestDefaultExpression<RawServer>, RawReplyDefaultExpression<RawServer>, ContextConfigDefault, FastifySchema, FastifyTypeProvider> = FastifyReply<RouteGenericInterface, RawServer, RawRequestDefaultExpression<RawServer>, RawReplyDefaultExpression<RawServer>, ContextConfigDefault, FastifySchema, FastifyTypeProviderDefault>
> {
serializers?: {
req?: (req: RawRequest) => {
method?: string;
url?: string;
version?: string;
host?: string;
remoteAddress?: string;
remotePort?: number;
[key: string]: unknown;
};
err?: (err: FastifyError) => {
type: string;
message: string;
stack: string;
[key: string]: unknown;
};
res?: (res: ResSerializerReply<RawServer, RawReply>) => {
statusCode?: string | number;
[key: string]: unknown;
};
};
level?: string;
file?: string;
genReqId?: (req: RawRequest) => string;
stream?: FastifyLoggerStreamDestination;
}
export interface FastifyChildLoggerFactory<
RawServer extends RawServerBase = RawServerDefault,
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
Logger extends FastifyBaseLogger = FastifyBaseLogger,
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault
> {
/**
* @param logger The parent logger
* @param bindings The bindings object that will be passed to the child logger
* @param childLoggerOpts The logger options that will be passed to the child logger
* @param rawReq The raw request
* @this The fastify instance
* @returns The child logger instance
*/
(
this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
logger: Logger,
bindings: Bindings,
childLoggerOpts: ChildLoggerOptions,
rawReq: RawRequest
): Logger
}