diff --git a/types/koa-bunyan-logger/index.d.ts b/types/koa-bunyan-logger/index.d.ts index 40c02a4faf..84a5cb0631 100644 --- a/types/koa-bunyan-logger/index.d.ts +++ b/types/koa-bunyan-logger/index.d.ts @@ -39,8 +39,14 @@ declare namespace koaBunyanLogger { ignorePath?: string[]; } + interface TimeContextOptions { + logLevel?: string; + updateLogFields?: (fields: any) => any; + } + function requestLogger(opts?: RequestLoggerOptions): Middleware; function requestIdContext(opts?: RequestIdContextOptions): Middleware; + function timeContext(opts?: TimeContextOptions): Middleware; } // Extend the Koa context to add the logger.. diff --git a/types/koa-bunyan-logger/koa-bunyan-logger-tests.ts b/types/koa-bunyan-logger/koa-bunyan-logger-tests.ts index 509e6759f3..739faab5f2 100644 --- a/types/koa-bunyan-logger/koa-bunyan-logger-tests.ts +++ b/types/koa-bunyan-logger/koa-bunyan-logger-tests.ts @@ -6,6 +6,20 @@ app.use(koaBunyanLogger()); app.use(koaBunyanLogger.requestIdContext()); app.use(koaBunyanLogger.requestLogger()); app.use(koaBunyanLogger.requestLogger({ ignorePath: ['/ping'] })); +app.use(koaBunyanLogger.timeContext()); +app.use( + koaBunyanLogger.timeContext({ + logLevel: 'warn', + updateLogFields(fields) { + return { + request_trace: { + name: fields.label, + time: fields.duration, + }, + }; + }, + }), +); app.use(async (ctx, next) => { ctx.log.info('Got a request from %s for %s', ctx.request.ip, ctx.path);