UNPKG

unnbound-logger-sdk

Version:

A structured logging library with TypeScript support using Pino. Provides consistent, well-typed logging with automatic logId, workflowId, traceId, and deploymentId tracking across operational contexts.

125 lines (124 loc) 4.61 kB
import { LogLevel, LoggerOptions, GeneralLogOptions, HttpRequestLogOptions, HttpResponseLogOptions, SftpTransactionLogOptions, DbQueryTransactionLogOptions, Log, HttpRequestLog, HttpResponseLog, SftpTransactionLog, DbQueryTransactionLog } from './types'; import { Request, Response, NextFunction } from 'express'; import { InternalAxiosRequestConfig } from 'axios'; declare module 'axios' { interface InternalAxiosRequestConfig { metadata?: { startTime: number; requestId?: string; }; } } /** * UnnboundLogger provides typed, structured logging using Pino */ export declare class UnnboundLogger { private logger; private workflowId; private workflowUrl; private serviceId; private deploymentId; private traceHeaderKey; private ignoreTraceRoutes; private ignoreAxiosTraceRoutes; /** * Creates a new UnnboundLogger instance * @param options - Configuration options for the logger */ constructor(options?: LoggerOptions); /** * Checks if a path matches any of the ignore patterns * @param path - The path to check * @param patterns - Array of glob patterns to match against * @returns boolean indicating if the path should be ignored */ private shouldIgnorePath; /** * Logs a general message * @param level - Log level * @param message - Log message * @param options - Additional logging options */ log(level: LogLevel, message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): Log; /** * Logs an error message * @param message - Error message or object * @param options - Additional logging options */ error(message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): Log; /** * Logs a warning message * @param message - Warning message * @param options - Additional logging options */ warn(message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): Log; /** * Logs an info message * @param message - Info message * @param options - Additional logging options */ info(message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): Log; /** * Logs a debug message * @param message - Debug message * @param options - Additional logging options */ debug(message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): Log; /** * Constructs the full URL from request information * @param req - Express request object * @returns Full URL string */ private constructFullUrl; /** * Logs an HTTP request * @param req - Express request object * @param options - Additional logging options * @returns The request ID for correlating with the response */ httpRequest(req: Request, options?: HttpRequestLogOptions): HttpRequestLog; /** * Logs an HTTP response * @param res - Express response object * @param req - Express request object * @param options - Additional logging options */ httpResponse(res: Response, req: Request, options?: HttpResponseLogOptions): HttpResponseLog; /** * Logs an SFTP transaction * @param operation - SFTP operation details * @param options - Additional logging options */ sftpTransaction(operation: { host: string; username: string; operation: 'upload' | 'download' | 'list' | 'delete' | 'rename' | 'stat'; path: string; status: 'success' | 'failure'; bytesTransferred?: number; filesListed?: number; sourcePath?: string; }, options?: SftpTransactionLogOptions): SftpTransactionLog; /** * Logs a database query transaction * @param query - Database query details * @param options - Additional logging options */ dbQueryTransaction(query: { instance: string; vendor: 'postgres' | 'mysql' | 'mssql' | 'mongodb'; query?: string; status: 'success' | 'failure'; rowsReturned?: number; rowsAffected?: number; }, options?: DbQueryTransactionLogOptions): DbQueryTransactionLog; traceMiddleware: (req: Request, res: Response, next: NextFunction) => void; axiosTraceMiddleware: { onFulfilled: (config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig; onRejected: (error: any) => any; }; axiosResponseInterceptor: { onFulfilled: (response: any) => any; onRejected: (error: any) => any; }; }