UNPKG

kobp

Version:
43 lines (42 loc) 1.41 kB
import { Middleware } from 'koa'; import type { Logger } from '.'; import { KobpServiceContext } from '..'; import { Tracer } from './tracer'; export interface PrintContent { requestId: string; user: any; ip: string[]; path: string; version: string; platform: string; app: string; method: string; statusCode: string | number; message?: string; error?: string; verdict: 'OK' | 'ER' | 'PG'; } export declare type PrintFn = (content: PrintContent) => void; export declare class Loggy extends Tracer implements Logger { static format: 'JSN' | 'TXT'; static customPrintLn?: PrintFn; private _printLn; constructor(ctx: KobpServiceContext, printFn?: PrintFn); /** * Override the print function */ setPrintFn(printLn: PrintFn): void; success(...messageParts: any[]): void; failed(message: string, error?: string | Error): void; log(...messageParts: any[]): void; error(message: string, error?: string | Error): void; private _print; static log(...messageParts: any[]): void; static error(message: string, error?: string | Error): void; static current(): Loggy; /** * the dirty way to prematurly create the Loggy instance manually via middleware * so that the instance is being ready before the RequestContext is ready. */ static autoCreate(attachToContextKey: string): Middleware; }