-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
129 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Type definitions for pino-http 6.0 | ||
// Project: https://github.com/pinojs/pino-http#readme | ||
// Definitions by: Christian Rackerseder <https://github.com/screendriver> | ||
// Jeremy Forsythe <https://github.com/jdforsythe> | ||
// Griffin Yourick <https://github.com/tough-griff> | ||
// Jorge Barnaby <https://github.com/yorch> | ||
// Jose Ramirez <https://github.com/jarcodallo> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
// TypeScript Version: 4.0 | ||
/// <reference types="node"/> | ||
|
||
import { IncomingMessage, ServerResponse } from 'http'; | ||
import pino from 'pino'; | ||
import { SerializedError, SerializedRequest, SerializedResponse } from 'pino-std-serializers'; | ||
|
||
declare function pinoHttp(opts?: Options, stream?: pino.DestinationStream): HttpLogger; | ||
|
||
declare function pinoHttp(stream?: pino.DestinationStream): HttpLogger; | ||
|
||
interface HttpLogger { | ||
(req: IncomingMessage, res: ServerResponse, next?: () => void): void; | ||
logger: pino.Logger; | ||
} | ||
type ReqId = number | string | object; | ||
|
||
interface Options extends pino.LoggerOptions { | ||
logger?: pino.Logger | undefined; | ||
genReqId?: GenReqId | undefined; | ||
useLevel?: pino.Level | undefined; | ||
stream?: pino.DestinationStream | undefined; | ||
autoLogging?: boolean | AutoLoggingOptions | undefined; | ||
customLogLevel?: ((res: ServerResponse, error: Error) => pino.Level) | undefined; | ||
customSuccessMessage?: ((res: ServerResponse) => string) | undefined; | ||
customErrorMessage?: ((error: Error, res: ServerResponse) => string) | undefined; | ||
customAttributeKeys?: CustomAttributeKeys | undefined; | ||
wrapSerializers?: boolean | undefined; | ||
reqCustomProps?: ((req: IncomingMessage, res: ServerResponse) => object) | undefined; | ||
quietReqLogger?: boolean | undefined; | ||
} | ||
|
||
interface GenReqId { | ||
(req: IncomingMessage): ReqId; | ||
} | ||
|
||
interface AutoLoggingOptions { | ||
ignore?: ((req: IncomingMessage) => boolean); | ||
ignorePaths?: Array<string | RegExp> | undefined; | ||
getPath?: ((req: IncomingMessage) => string | undefined) | undefined; | ||
} | ||
|
||
interface CustomAttributeKeys { | ||
req?: string | undefined; | ||
res?: string | undefined; | ||
err?: string | undefined; | ||
reqId?: string | undefined; | ||
responseTime?: string | undefined; | ||
} | ||
|
||
interface StdSerializers { | ||
err: SerializedError; | ||
req: SerializedRequest; | ||
res: SerializedResponse; | ||
} | ||
|
||
export default pinoHttp; | ||
|
||
export const startTime: unique symbol; | ||
|
||
export const stdSerializers: StdSerializers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
/// <reference path="./index.d.ts"/> | ||
|
||
import { Writable } from 'stream'; | ||
import { IncomingMessage, ServerResponse } from 'http'; | ||
import pino from 'pino'; | ||
import pinoHttp from './'; | ||
|
||
const logger = pino(); | ||
|
||
pinoHttp({ logger }); | ||
pinoHttp({ logger }).logger = logger; | ||
pinoHttp({ genReqId: (req: IncomingMessage) => req.statusCode || 200 }); | ||
pinoHttp({ genReqId: (req: IncomingMessage) => 'foo' }); | ||
pinoHttp({ genReqId: (req: IncomingMessage) => Buffer.allocUnsafe(16) }); | ||
pinoHttp({ useLevel: 'error' }); | ||
pinoHttp({ prettyPrint: true }); // deprecated but still present in pino. | ||
pinoHttp({ transport: { target: 'pino-pretty', options: { colorize: true } } }); | ||
pinoHttp({ autoLogging: false }); | ||
pinoHttp({ autoLogging: { ignore: (req: IncomingMessage) => req.headers['user-agent'] === 'ELB-HealthChecker/2.0' } }); | ||
pinoHttp({ autoLogging: { ignorePaths: ['/health'] } }); | ||
pinoHttp({ autoLogging: { ignorePaths: [/\/health/] } }); | ||
pinoHttp({ autoLogging: { ignorePaths: ['/health'], getPath: (req: IncomingMessage) => req.url } }); | ||
pinoHttp({ customSuccessMessage: (req: ServerResponse) => 'Success' }); | ||
pinoHttp({ customErrorMessage: (error: Error, res: ServerResponse) => `Error - ${error}` }); | ||
pinoHttp({ customAttributeKeys: { req: 'req' } }); | ||
pinoHttp({ customAttributeKeys: { res: 'res' } }); | ||
pinoHttp({ customAttributeKeys: { err: 'err' } }); | ||
pinoHttp({ customAttributeKeys: { responseTime: 'responseTime' } }); | ||
pinoHttp({ customAttributeKeys: { req: 'req', res: 'res', err: 'err', responseTime: 'responseTime' } }); | ||
pinoHttp({ customLogLevel: (res: ServerResponse, error: Error) => 'info' }); | ||
pinoHttp({ reqCustomProps: (req: IncomingMessage, res: ServerResponse) => ({ key1: 'value1', 'x-key-2': 'value2' }) }); | ||
pinoHttp({ wrapSerializers: false }); | ||
pinoHttp(new Writable()); | ||
pinoHttp({ quietReqLogger: true, customAttributeKeys: { reqId: 'reqId' }}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es6", | ||
"esModuleInterop": true, | ||
"lib": [ "es2015" ], | ||
"module": "commonjs", | ||
"noEmit": true, | ||
"strict": true, | ||
"moduleResolution": "node", | ||
}, | ||
"include": [ | ||
"./*.test-d.ts", | ||
"./*.d.ts" | ||
] | ||
} |