mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 20:40:20 +00:00
update pino-http and koa-pino-logger signatures to match documented APIs
This commit is contained in:
Vendored
+5
-12
@@ -7,25 +7,18 @@
|
||||
/// <reference types="node"/>
|
||||
|
||||
import { Middleware } from 'koa';
|
||||
import { LoggerOptions, Logger, Level } from 'pino';
|
||||
import { DestinationStream, LoggerOptions, Logger, Level } from 'pino';
|
||||
import { Options } from 'pino-http';
|
||||
import * as stream from 'stream';
|
||||
import * as http from 'http';
|
||||
|
||||
export = logger;
|
||||
|
||||
declare function logger(
|
||||
opts?: logger.HttpLoggerOptions,
|
||||
stream?: stream.Writable | stream.Duplex | stream.Transform
|
||||
opts?: Options,
|
||||
stream?: DestinationStream
|
||||
): Middleware;
|
||||
|
||||
declare namespace logger {
|
||||
interface HttpLoggerOptions extends LoggerOptions {
|
||||
logger?: Logger;
|
||||
genReqId?(req: http.IncomingMessage): number;
|
||||
useLevel?: Level;
|
||||
stream?: stream.Writable | stream.Duplex | stream.Transform;
|
||||
}
|
||||
}
|
||||
declare function logger(stream?: DestinationStream): Middleware;
|
||||
|
||||
declare module 'koa' {
|
||||
interface Context {
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import koa = require('koa');
|
||||
import logger = require('koa-pino-logger');
|
||||
import { Writable } from 'stream';
|
||||
|
||||
const app = new koa();
|
||||
app.use(logger());
|
||||
app.use(logger(new Writable()));
|
||||
app.use(logger({stream: new Writable()}));
|
||||
app.use(logger({genReqId: () => 'foo'}));
|
||||
|
||||
app.use((ctx) => {
|
||||
ctx.log.info('something else');
|
||||
|
||||
Vendored
+9
-3
@@ -5,19 +5,25 @@
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
import { IncomingMessage, ServerResponse } from 'http';
|
||||
import { Level, Logger, LoggerOptions } from 'pino';
|
||||
import { DestinationStream, Level, Logger, LoggerOptions } from 'pino';
|
||||
|
||||
export = PinoHttp;
|
||||
|
||||
declare function PinoHttp(opts?: PinoHttp.Options): PinoHttp.HttpLogger;
|
||||
declare function PinoHttp(opts?: PinoHttp.Options, stream?: DestinationStream): PinoHttp.HttpLogger;
|
||||
declare function PinoHttp(stream?: DestinationStream): PinoHttp.HttpLogger;
|
||||
|
||||
declare namespace PinoHttp {
|
||||
type HttpLogger = (req: IncomingMessage, res: ServerResponse) => void;
|
||||
|
||||
interface Options extends LoggerOptions {
|
||||
logger?: Logger;
|
||||
genReqId?: (req: IncomingMessage) => number;
|
||||
genReqId?: GenReqId;
|
||||
useLevel?: Level;
|
||||
stream?: DestinationStream;
|
||||
}
|
||||
|
||||
interface GenReqId {
|
||||
(req: IncomingMessage): number | string | object;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import http = require('http');
|
||||
import pino = require('pino');
|
||||
import pinoHttp = require('pino-http');
|
||||
import { Writable } from 'stream';
|
||||
|
||||
const logger = pino();
|
||||
const httpLogger = pinoHttp();
|
||||
@@ -12,5 +13,8 @@ function handle(req: http.IncomingMessage, res: http.ServerResponse) {
|
||||
|
||||
pinoHttp({ logger });
|
||||
pinoHttp({ genReqId: (req) => req.statusCode || 200 });
|
||||
pinoHttp({ genReqId: (req) => 'foo' });
|
||||
pinoHttp({ genReqId: (req) => Buffer.allocUnsafe(16) });
|
||||
pinoHttp({ useLevel: 'error' });
|
||||
pinoHttp({ prettyPrint: true });
|
||||
pinoHttp(new Writable());
|
||||
|
||||
Vendored
+3
-2
@@ -23,7 +23,7 @@ export = P;
|
||||
* relative protocol is enabled. Default: process.stdout
|
||||
* @returns a new logger instance.
|
||||
*/
|
||||
declare function P(optionsOrStream?: P.LoggerOptions | stream.Writable | stream.Duplex | stream.Transform | NodeJS.WritableStream | SonicBoom): P.Logger;
|
||||
declare function P(optionsOrStream?: P.LoggerOptions | P.DestinationStream): P.Logger;
|
||||
|
||||
/**
|
||||
* @param [options]: an options object
|
||||
@@ -31,7 +31,7 @@ declare function P(optionsOrStream?: P.LoggerOptions | stream.Writable | stream.
|
||||
* relative protocol is enabled. Default: process.stdout
|
||||
* @returns a new logger instance.
|
||||
*/
|
||||
declare function P(options: P.LoggerOptions, stream: stream.Writable | stream.Duplex | stream.Transform | NodeJS.WritableStream | SonicBoom): P.Logger;
|
||||
declare function P(options: P.LoggerOptions, stream: P.DestinationStream): P.Logger;
|
||||
|
||||
declare namespace P {
|
||||
/**
|
||||
@@ -127,6 +127,7 @@ declare namespace P {
|
||||
labels: { [level: number]: string; };
|
||||
}
|
||||
type TimeFn = () => string;
|
||||
type DestinationStream = stream.Writable | stream.Duplex | stream.Transform | NodeJS.WritableStream | SonicBoom;
|
||||
|
||||
interface LoggerOptions {
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user