UNPKG

@logtail/next

Version:

Better Stack Telemetry Next.js client

105 lines (104 loc) 2.78 kB
import { NextRequest } from 'next/server'; import { NetlifyInfo } from './platform/netlify'; import { type RequestJSON } from './shared'; export interface LogEvent { level: string; message: string; fields: any; dt: string; request?: RequestReport; git?: any; source: string; platform?: PlatformInfo; vercel?: PlatformInfo; netlify?: NetlifyInfo; '@app': { 'next-logtail-version': string; }; } export declare enum LogLevel { debug = 0, info = 1, warn = 2, error = 3, off = 100 } export interface RequestReport { startTime: number; endTime: number; statusCode?: number; ip?: string | null; region?: string | null; path: string; host?: string | null; method: string; scheme: string; userAgent?: string | null; durationMs?: number; details?: RequestJSON; } export interface PlatformInfo { environment?: string; region?: string; route?: string; source?: string; deploymentId?: string; deploymentUrl?: string; commit?: string; project?: string; repo?: string; ref?: string; git?: { commit?: string; repo?: string; ref?: string; }; } export type LoggerConfig = { args?: { [key: string]: any; }; logLevel?: LogLevel; autoFlush?: boolean; source?: string; req?: any; prettyPrint?: typeof prettyPrint; }; export declare class Logger { initConfig: LoggerConfig; logEvents: LogEvent[]; throttledSendLogs: (this: any) => void; children: Logger[]; logLevel: LogLevel; config: LoggerConfig; constructor(initConfig?: LoggerConfig); debug: (message: string, args?: { [key: string]: any; }) => void; info: (message: string, args?: { [key: string]: any; }) => void; warn: (message: string, args?: { [key: string]: any; }) => void; error: (message: string, args?: { [key: string]: any; }) => void; with: (args: { [key: string]: any; }) => Logger; withRequest: (req: any) => Logger; private _transformEvent; logHttpRequest(level: LogLevel, message: string, request: any, args: any): void; middleware<TConfig extends { logRequestDetails?: boolean | (keyof RequestJSON)[]; }, TReturn = TConfig['logRequestDetails'] extends boolean | (keyof RequestJSON)[] ? Promise<void> : void>(request: NextRequest, config?: TConfig): TReturn; log: (level: LogLevel, message: string, args?: { [key: string]: any; }) => void; attachResponseStatus: (statusCode: number) => void; sendLogs(): Promise<any>; flush: () => Promise<void>; } export declare const log: Logger; export declare function prettyPrint(ev: LogEvent): void;