UNPKG

2.72 kBTypeScriptView Raw
1// Type definitions for pino-http 5.8
2// Project: https://github.com/pinojs/pino-http#readme
3// Definitions by: Christian Rackerseder <https://github.com/screendriver>
4// Jeremy Forsythe <https://github.com/jdforsythe>
5// Griffin Yourick <https://github.com/tough-griff>
6// Jorge Barnaby <https://github.com/yorch>
7// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
8// TypeScript Version: 2.7
9
10import { IncomingMessage, ServerResponse } from 'http';
11import { DestinationStream, Level, Logger, LoggerOptions } from 'pino';
12
13export = PinoHttp;
14
15declare function PinoHttp(opts?: PinoHttp.Options, stream?: DestinationStream): PinoHttp.HttpLogger;
16declare function PinoHttp(stream?: DestinationStream): PinoHttp.HttpLogger;
17
18declare namespace PinoHttp {
19 interface HttpLogger {
20 (req: IncomingMessage, res: ServerResponse, next?: () => void): void;
21 logger: Logger;
22 }
23 type ReqId = number | string | object;
24
25 /**
26 * Options for pino-http
27 *
28 * See https://github.com/pinojs/pino-http#pinohttpopts-stream
29 */
30 interface Options extends LoggerOptions {
31 logger?: Logger | undefined;
32 genReqId?: GenReqId | undefined;
33 useLevel?: Level | undefined;
34 stream?: DestinationStream | undefined;
35 autoLogging?: boolean | AutoLoggingOptions | undefined;
36 customLogLevel?: ((res: ServerResponse, error: Error) => Level) | undefined;
37 customSuccessMessage?: ((res: ServerResponse) => string) | undefined;
38 customErrorMessage?: ((error: Error, res: ServerResponse) => string) | undefined;
39 customAttributeKeys?: CustomAttributeKeys | undefined;
40 wrapSerializers?: boolean | undefined;
41 reqCustomProps?: ((req: IncomingMessage, res: ServerResponse) => object) | undefined;
42 quietReqLogger?: boolean | undefined;
43 }
44
45 interface GenReqId {
46 (req: IncomingMessage): ReqId;
47 }
48
49 interface AutoLoggingOptions {
50 ignore?: ((req: IncomingMessage) => boolean);
51 ignorePaths?: Array<string | RegExp> | undefined;
52 getPath?: ((req: IncomingMessage) => string | undefined) | undefined;
53 }
54
55 interface CustomAttributeKeys {
56 req?: string | undefined;
57 res?: string | undefined;
58 err?: string | undefined;
59 reqId?: string | undefined;
60 responseTime?: string | undefined;
61 }
62
63 const startTime: unique symbol;
64}
65
66declare module 'http' {
67 interface IncomingMessage {
68 id: PinoHttp.ReqId;
69 log: Logger;
70 }
71
72 interface ServerResponse {
73 err?: Error | undefined;
74 }
75
76 interface OutgoingMessage {
77 [PinoHttp.startTime]: number;
78 }
79}
80
\No newline at end of file