firstlog
Version:
Modern middleware based logger for Express.js
52 lines (51 loc) • 1.33 kB
TypeScript
import "source-map-support/register";
import type { Request, Response, NextFunction } from "express";
export interface Origin {
file?: string;
func?: string;
}
export interface LoggerOptions {
logFile: string;
maskFields?: string[];
captureBody?: boolean;
trackQuery?: boolean;
onlyLogOnError?: boolean;
maxBodySize?: number;
trackUser?: (req: Request) => string;
trackOrigin?: boolean;
onLog?: (logEntry: LogEntry) => void;
enableGeoIP?: boolean;
slowThresholdMs?: number;
trackSlow?: boolean;
requestIdHeader?: string;
prettyPrint?: boolean;
logHeaders?: boolean;
logParams?: boolean;
logResponseBody?: boolean;
excludePaths?: string[];
}
interface LogEntry {
requestId: string;
timestamp: string;
method: string;
route: string;
status: number;
ip?: string;
durationMs?: number;
slow?: boolean;
user?: string;
body?: any;
query?: any;
responseSnippet?: string;
origin?: Origin;
location?: {
country?: string;
region?: string;
city?: string;
};
headers?: any;
params?: any;
}
export type ExpressMiddleware = (req: Request, res: Response, next: NextFunction) => void;
export declare function logger(options: LoggerOptions): ExpressMiddleware;
export {};