mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 04:50:18 +00:00
[@types/hapi-pino] fix/improve types, improve tests (#39219)
* [@types/hapi-pino] fix/improve types, improve tests * [@types/hapi-pino] Update to hapi-pino to 6.3
This commit is contained in:
committed by
Wesley Wigham
parent
227454ec9f
commit
64305fc7f9
@@ -1,4 +1,4 @@
|
||||
import { Server } from '@hapi/hapi';
|
||||
import { Request, Server } from '@hapi/hapi';
|
||||
import * as pino from 'pino';
|
||||
import * as HapiPino from 'hapi-pino';
|
||||
|
||||
@@ -6,39 +6,79 @@ const pinoLogger = pino();
|
||||
|
||||
const server = new Server();
|
||||
|
||||
server.register({
|
||||
plugin: HapiPino,
|
||||
options: {
|
||||
logPayload: false,
|
||||
logRouteTags: false,
|
||||
stream: process.stdout,
|
||||
prettyPrint: process.env.NODE_ENV !== 'PRODUCTION',
|
||||
levelTags: {
|
||||
trace: 'trace',
|
||||
debug: 'debug',
|
||||
info: 'info',
|
||||
warn: 'warn',
|
||||
error: 'error'
|
||||
function example1() {
|
||||
server
|
||||
.register({
|
||||
plugin: HapiPino,
|
||||
options: {
|
||||
logPayload: false,
|
||||
logRouteTags: false,
|
||||
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),
|
||||
},
|
||||
instance: pinoLogger,
|
||||
logEvents: false,
|
||||
mergeHapiLogData: false,
|
||||
ignorePaths: ['/testRoute'],
|
||||
level: 'debug',
|
||||
redact: ['test.property'],
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
server.logger().debug('using logger object directly');
|
||||
|
||||
server.route({
|
||||
method: 'GET',
|
||||
path: '/',
|
||||
handler: (request, h) => {
|
||||
request.logger.debug('using logger directly');
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function example2() {
|
||||
server.register({
|
||||
plugin: HapiPino,
|
||||
options: {
|
||||
redact: {
|
||||
paths: ['test.property', 'another.property'],
|
||||
remove: true,
|
||||
},
|
||||
logRequestStart: true,
|
||||
prettyPrint: {
|
||||
levelFirst: true,
|
||||
colorize: true,
|
||||
translateTime: 'SYS:yyyy-mm-dd HH:MM:ss.l',
|
||||
ignore: 'hostname,pid',
|
||||
},
|
||||
getChildBindings: (req: Request) => ({
|
||||
'x-request-id': req.headers['x-request-id'],
|
||||
}),
|
||||
},
|
||||
allTags: 'info',
|
||||
serializers: {
|
||||
req: (req: any) => console.log(req)
|
||||
},
|
||||
instance: pinoLogger,
|
||||
logEvents: false,
|
||||
mergeHapiLogData: false,
|
||||
});
|
||||
}
|
||||
|
||||
function example3() {
|
||||
HapiPino.register(server, {
|
||||
ignorePaths: ['/testRoute'],
|
||||
level: 'debug',
|
||||
redact: ['test.property']
|
||||
}
|
||||
}).then(() => {
|
||||
server.logger().debug('using logger object directly');
|
||||
|
||||
server.route({
|
||||
method: 'GET',
|
||||
path: '/',
|
||||
handler: (request, h) => {
|
||||
request.logger.debug('using logger directly');
|
||||
}
|
||||
tags: {
|
||||
trace: 'trace',
|
||||
debug: 'debug',
|
||||
},
|
||||
redact: ['test.property'],
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Vendored
+20
-9
@@ -1,7 +1,8 @@
|
||||
// Type definitions for hapi-pino 6.0
|
||||
// Type definitions for hapi-pino 6.3
|
||||
// Project: https://github.com/pinojs/hapi-pino#readme
|
||||
// Definitions by: Rodrigo Saboya <https://github.com/saboya>
|
||||
// Todd Bealmear <https://github.com/todd>
|
||||
// Matt Jeanes <https://github.com/BlooJeans>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
@@ -9,7 +10,7 @@
|
||||
|
||||
import * as pino from 'pino';
|
||||
|
||||
import { Plugin } from '@hapi/hapi';
|
||||
import { Plugin, Request } from '@hapi/hapi';
|
||||
|
||||
declare module '@hapi/hapi' {
|
||||
interface Server {
|
||||
@@ -22,22 +23,32 @@ declare module '@hapi/hapi' {
|
||||
}
|
||||
|
||||
declare namespace HapiPino {
|
||||
type LogLevels = 'trace' | 'debug' | 'info' | 'warn' | 'error';
|
||||
interface Serializers {
|
||||
[key: string]: pino.SerializerFn;
|
||||
}
|
||||
|
||||
interface Options {
|
||||
logPayload?: boolean;
|
||||
logRouteTags?: boolean;
|
||||
logRequestStart?: boolean;
|
||||
stream?: NodeJS.WriteStream;
|
||||
prettyPrint?: boolean;
|
||||
levelTags?: { [key in LogLevels]: string };
|
||||
allTags?: LogLevels;
|
||||
serializers?: { [key: string]: (param: any) => void};
|
||||
prettyPrint?: boolean | pino.PrettyOptions;
|
||||
tags?: { [key in pino.Level]?: string };
|
||||
allTags?: pino.Level;
|
||||
serializers?: Serializers;
|
||||
getChildBindings?: (
|
||||
req: Request,
|
||||
) => {
|
||||
level?: pino.Level | string;
|
||||
serializers?: Serializers;
|
||||
[key: string]: any;
|
||||
};
|
||||
instance?: pino.Logger;
|
||||
logEvents?: string[] | false | null;
|
||||
mergeHapiLogData?: boolean;
|
||||
ignorePaths?: string[];
|
||||
level?: LogLevels;
|
||||
redact?: string[];
|
||||
level?: pino.Level;
|
||||
redact?: string[] | pino.redactOptions;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user