Add types for express-bunyan-logger module.

This commit is contained in:
shrey 2018-03-04 12:46:27 -05:00
parent 420e0d5d29
commit c8f7a59cc8
4 changed files with 82 additions and 0 deletions

View File

@ -0,0 +1,24 @@
import Bunyan = require('bunyan');
import expressBunyan = require('express-bunyan-logger');
// works with no options
const middleware = expressBunyan({});
const middleware2 = expressBunyan.errorLogger({});
// format accepts both string and function
const middleware3 = expressBunyan({
format: ':name'
});
const middleware4 = expressBunyan({
format(meta: any) {
return 'foo';
}
});
// works when provided a bunyan logger
const logger = Bunyan.createLogger({
name: 'myLogger'
});
const middleware5 = expressBunyan({
logger
});

34
types/express-bunyan-logger/index.d.ts vendored Normal file
View File

@ -0,0 +1,34 @@
// Type definitions for express-bunyan-logger 1.3
// Project: https://github.com/villadora/express-bunyan-logger
// Definitions by: Shrey Jain <https://github.com/shreyjain1994>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import Bunyan = require('bunyan');
import express = require('express');
export = Factory;
declare function Factory(options?: Factory.Options): express.RequestHandler;
declare namespace Factory {
type FormatFunction = (meta: any) => string;
type IncludesFunction = (req: express.Request, res: express.Response) => any;
type RequestIdGenFunction = (req: express.Request) => string;
type LevelFunction = (status: number, err: Error | null, meta: any) => string;
interface Options {
logger?: Bunyan;
format?: string | FormatFunction;
parseUA?: boolean;
levelFn?: LevelFunction;
includesFn?: IncludesFunction;
excludes?: string[];
obfuscate?: string[];
obfuscatePlaceholder?: string;
serializers?: { [field: string]: Bunyan.Serializer };
immediate?: boolean;
genReqId?: RequestIdGenFunction;
}
function errorLogger(options?: Options): express.ErrorRequestHandler;
}

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",
"express-bunyan-logger-tests.ts"
]
}

View File

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