mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 12:30:18 +00:00
Add koaBunyanLogger.timeContext(opts) (#41977)
https://github.com/koajs/bunyan-logger#koabunyanloggertimecontextopts > koaBunyanLogger.timeContext(opts) > Adds time(label) and timeEnd(label) methods to the koa context, which records the time between the time() and timeEnd() calls for a given label. > > Calls to time() and timeEnd() can be nested or interleaved as long as they're balanced for each label. > > Options: > > logLevel: name of log level to use; defaults to 'trace' > updateLogFields: function which will be called with arguments (fields) in koa context; can update fields or return a new object.
This commit is contained in:
Vendored
+6
@@ -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..
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user