Adding types for hapi-pino.

This commit is contained in:
Rodrigo Saboya
2018-12-12 16:53:23 -02:00
parent cca60bd544
commit 6051594a61
4 changed files with 114 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
import { Server } from 'hapi';
import * as pino from 'pino';
import * as HapiPino from 'hapi-pino';
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'
},
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');
}
});
});

46
types/hapi-pino/index.d.ts vendored Normal file
View File

@@ -0,0 +1,46 @@
// Type definitions for hapi-pino 5.2
// Project: https://github.com/pinojs/hapi-pino#readme
// Definitions by: Rodrigo Saboya <https://github.com/saboya>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
/// <reference types='node' />
import {
Plugin,
} from 'hapi';
import * as pino from 'pino';
declare module 'hapi' {
interface Server {
logger: () => pino.Logger;
}
interface Request {
logger: pino.Logger;
}
}
declare namespace HapiPino {
type LogLevels = 'trace' | 'debug' | 'info' | 'warn' | 'error';
interface Options {
logPayload?: boolean;
logRouteTags?: boolean;
stream?: NodeJS.WriteStream;
prettyPrint?: boolean;
levelTags?: { [key in LogLevels]: string };
allTags?: LogLevels;
serializers?: { [key: string]: (param: any) => void};
instance?: pino.Logger;
logEvents?: string[] | false | null;
mergeHapiLogData?: boolean;
ignorePaths?: string[];
level?: LogLevels;
redact?: string[];
}
}
declare var HapiPino: Plugin<HapiPino.Options>;
export = HapiPino;

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"hapi-pino-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }