-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add type declarations * Add types field in package.json * Remove DefinitelyTyped url * Add new options * Adds test for types * No need to redeclare module * Revert "No need to redeclare module" This reverts commit 4462d99. * Include types test in CI Co-authored-by: Luke Grunau <[email protected]> Co-authored-by: Luke Grunau <[email protected]>
- Loading branch information
1 parent
8240968
commit b960b85
Showing
3 changed files
with
112 additions
and
2 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,62 @@ | ||
// Type definitions for hapi-pino 9.0 | ||
// Definitions by: Rodrigo Saboya <https://github.com/saboya> | ||
// Todd Bealmear <https://github.com/todd> | ||
// Matt Jeanes <https://github.com/BlooJeans> | ||
// Kyle Gray <https://github.com/GoPro16> | ||
// TypeScript Version: 2.8 | ||
|
||
/// <reference types='node' /> | ||
|
||
import type { pino } from 'pino'; | ||
|
||
import { Plugin, Request } from '@hapi/hapi'; | ||
|
||
declare module '@hapi/hapi' { | ||
interface Server { | ||
logger: pino.Logger; | ||
} | ||
|
||
interface Request { | ||
logger: pino.Logger; | ||
} | ||
} | ||
|
||
declare namespace HapiPino { | ||
interface Serializers { | ||
[key: string]: pino.SerializerFn; | ||
} | ||
|
||
interface Options { | ||
timestamp?: boolean | (() => string) | undefined; | ||
logQueryParams?: boolean | undefined; | ||
logPayload?: boolean | undefined; | ||
logRouteTags?: boolean | undefined; | ||
logRequestStart?: boolean | ((req: Request) => boolean) | undefined; | ||
logRequestComplete?: boolean | ((req: Request) => boolean) | undefined; | ||
stream?: NodeJS.WriteStream | undefined; | ||
prettyPrint?: boolean | pino.PrettyOptions | undefined; | ||
tags?: { [key in pino.Level]?: string } | undefined; | ||
allTags?: pino.Level | undefined; | ||
serializers?: Serializers | undefined; | ||
getChildBindings?: | ||
| ((req: Request) => { | ||
level?: pino.Level | string | undefined; | ||
serializers?: Serializers | undefined; | ||
[key: string]: any; | ||
}) | ||
| undefined; | ||
instance?: pino.Logger | undefined; | ||
logEvents?: string[] | false | null | undefined; | ||
mergeHapiLogData?: boolean | undefined; | ||
ignorePaths?: string[] | undefined; | ||
level?: pino.Level | undefined; | ||
redact?: string[] | pino.redactOptions | undefined; | ||
ignoreTags?: string[] | undefined; | ||
ignoreFunc?: ((options: Options, request: Request) => boolean) | undefined; | ||
ignoredEventTags?: object[] | undefined; | ||
} | ||
} | ||
|
||
declare var HapiPino: Plugin<HapiPino.Options>; | ||
|
||
export = HapiPino; |
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,45 @@ | ||
import { Request, Server } from '@hapi/hapi'; | ||
import pino from 'pino'; | ||
import * as HapiPino from '.'; | ||
import { expectType } from 'tsd'; | ||
|
||
const pinoLogger = pino(); | ||
|
||
const server = new Server(); | ||
|
||
const options: HapiPino.Options = { | ||
timestamp: () => `,"time":"${new Date(Date.now()).toISOString()}"`, | ||
logQueryParams: false, | ||
logPayload: false, | ||
logRouteTags: false, | ||
logRequestStart: false, | ||
logRequestComplete: true, | ||
stream: process.stdout, | ||
prettyPrint: process.env.NODE_ENV !== 'PRODUCTION', | ||
tags: { | ||
trace: 'trace', | ||
debug: 'debug', | ||
info: 'info', | ||
warn: 'warn', | ||
error: 'error', | ||
fatal: 'fatal', | ||
}, | ||
allTags: 'info', | ||
serializers: { | ||
req: (req: any) => console.log(req), | ||
}, | ||
getChildBindings: (req: Request) => ({ | ||
'x-request-id': req.headers['x-request-id'], | ||
}), | ||
instance: pinoLogger, | ||
logEvents: false, | ||
mergeHapiLogData: false, | ||
ignorePaths: ['/testRoute'], | ||
level: 'debug', | ||
redact: ['test.property'], | ||
ignoreTags: ['healthcheck'], | ||
ignoreFunc: (options, request) => request.path.startsWith('/static'), | ||
ignoredEventTags: [{ log: ['DEBUG', 'TEST'], request: ['DEBUG', 'TEST'] }], | ||
}; | ||
|
||
expectType<Promise<void>>(server.register({ plugin: HapiPino, options })); |
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