import { LogLevelType } from "./protocol.js"; /** * Timestamp format options */ export type TimestampType = "iso" | "locale" | "utc" | "unix" | "unix_ms" | "date" | "time" | "datetime" | "short" | "custom"; /** * Represents somthing you want to hide / mask */ export type LoggerMaskOptions = { /** * String value to match for token */ identifier?: string; /** * Regex to match for token */ regexIdentifier?: RegExp; /** * Token to replace the identified token with */ replaceToken?: string; /** * Use a custom function to replace a matched token * @param token The matched piece of text * @returns Masked string value to replace it with */ replacer?: (token: string) => string; /** * Which masker will win the mask should multiple mathc the same token higher number wins */ priority: number; }; /** * Options to change the logger */ export type LoggerOptions = { /** * Where to store the log files output */ basePath: string; /** * If this logger should save logs to log files */ saveToLogFiles: boolean; /** * If this logger's logs should be printed to the stdout of the process */ outputToConsole: boolean; /** * If the output to console should be colored */ useColoredOutput: boolean; /** * Map of specific log level and what color to use */ colorMap: Record; /** * If it should add timestamps to logs */ showTimestamps: boolean; /** * Which timestamp format to use (only applies when showTimestamps is true) */ timestampType: TimestampType; /** * If it should show log level */ showLogLevel: boolean; /** * Map a specific log level with a string value used for it */ logLevelMap: Record; /** * Show where it was called at (file:line:column) */ showCallSite?: boolean; /** * Addtional options to change call site log information */ callSiteOptions?: { /** * If it should show a full file path or the default short name */ fullFilePath?: boolean; /** * Custom stack frame offset to control which caller appears in logs. * * The logger automatically skips its own internal methods to show the actual * caller. Use this to adjust how far up the call stack to look. * * - 0 = The code that called logger.log() / logger.info() etc. * - 1 = The parent of the direct caller * - 2 = The grandparent of the direct caller * - undefined = Auto-detect (default behavior, skips logger internals) * * @example * // In a wrapper function, show the caller of your wrapper instead of the wrapper itself * function myWrapper(msg: string) { * logger.info(msg); // With frameIndex: 1, shows who called myWrapper() * } */ frameIndex?: number; }; /** * Contains a list of addtional prefixes to add to each log for example `["foo"]` */ additionalPrefixes?: string[]; /** * Contains a list of sensitive items that need to be redacted or removed in logs */ masks?: LoggerMaskOptions[]; }; /** * Custom error for logger initialization failures */ export declare class LoggerInitializationError extends Error { constructor(message: string); } /** * Used to log to console and also the log files */ export declare class Logger { /** * Local reference to options passed */ private _options; /** * Holds the worker thread */ private _worker; /** * A request's id */ private _id; /** * Gets the next ID; if it exceeds 1 million then rolls back to zero */ private _getNextId; /** * Holds batch of LOG requests only (fire-and-forget) */ private _logBatch; /** * How long it will wait until it flushes / sends the logs to the worker */ private _logRequestFlushMs; /** * Holds the timeout for log batch flushing */ private _logBatchTimeout; /** * How large we want the batch array to get before we send it */ private _logBatchMaxSize; /** * Holds pending requests that expect a response (FLUSH, RELOAD, SHUTDOWN) */ private _pending; constructor(options?: Partial); /** * Get the path to the worker * @returns Path to the worker */ private _getWorkerPath; /** * Inits the worker thread */ private _initWorker; /** * Flush the current log batch to worker immediately */ private _flushLogBatch; /** * Starts the timer to flush log batch after delay */ private _startLogBatchTimer; /** * Stops the log batch flush timer */ private _stopLogBatchTimer; /** * Adds a LOG request to the batch (fire-and-forget) */ private _addToLogBatch; /** * Clears pending requests on process exit/error */ private _clearPending; /** * Handle a decoded response from worker */ private _handleResponse; /** * Resolve any pending requests that expected a response */ private _resolvePending; /** * Send a request that expects a response (FLUSH, RELOAD, SHUTDOWN) * These are sent immediately, not batched */ private _sendControlRequest; /** * Validates the basePath option */ private _validateBasePath; /** * Extract call site information (file:line:column) from stack trace */ private _getCallSite; /** * Get the string representation of a log level */ private _getLevelString; /** * Format timestamp based on the configured timestampType */ private _formatTimestamp; /** * Convert any value to string representation */ private _stringify; /** * Format a log message with optional fields */ private _formatMessage; /** * Apply color to the entire message if colored output is enabled */ private _colorize; /** * Masks sensitive data in a formatted log message * @param message The formatted log message to mask * @returns Masked version of the message */ private _maskMessage; /** * Log a specific level and content * @param level The specific level to log * @param message The content of the message * @param messages Any additional messages */ private log; /** * Convenience method for INFO level */ info(message: any, ...messages: any[]): void; /** * Convenience method for WARN level */ warn(message: any, ...messages: any[]): void; /** * Convenience method for ERROR level */ error(message: any, ...messages: any[]): void; /** * Convenience method for DEBUG level */ debug(message: any, ...messages: any[]): void; /** * Convenience method for FATAL level */ fatal(message: any, ...messages: any[]): void; /** * Flush remaining buffer to log files */ flush(): Promise; /** * Used to reload / refresh the process */ reload(): Promise; /** * Used to shut down the child process and clean up, doing so will close the process used to batch logs to files, however, logs to the console will * still go through after calling this */ shutdown(): Promise; } //# sourceMappingURL=logger.d.ts.map