UNPKG

@superbuilders/slog

Version:

Simple structured logging library

73 lines 2.6 kB
/** * High-performance structured logging library inspired by Go's slog. * * Features: * - Structured logging with key-value attributes * - Automatic toString() handling for objects with custom toString methods * - Configurable log levels * * Basic usage: * ```typescript * import * as logger from './slog' * * logger.info("user logged in", { userId: "123", ip: "192.168.1.1" }) * logger.error("database connection failed", { error: err }) * ``` */ /** * Log levels following slog convention. * Lower numbers indicate more verbose logging. */ declare enum LogLevel { DEBUG = -4, INFO = 0, WARN = 4, ERROR = 8 } /** * Convenient constants for log levels */ export declare const DEBUG = LogLevel.DEBUG; export declare const INFO = LogLevel.INFO; export declare const WARN = LogLevel.WARN; export declare const ERROR = LogLevel.ERROR; /** * Set the minimum log level. Messages below this level will be ignored. * @param level The minimum log level to output */ export declare function setDefaultLogLevel(level: typeof DEBUG | typeof INFO | typeof WARN | typeof ERROR): void; /** * Log a debug message with optional structured attributes. * @param message The log message * @param attributes Optional key-value pairs for structured logging */ export declare function debug(message: string, attributes?: Record<string, unknown>): void; /** * Log an info message with optional structured attributes. * @param message The log message * @param attributes Optional key-value pairs for structured logging */ export declare function info(message: string, attributes?: Record<string, unknown>): void; /** * Log a warning message with optional structured attributes. * @param message The log message * @param attributes Optional key-value pairs for structured logging */ export declare function warn(message: string, attributes?: Record<string, unknown>): void; /** * Log an error message with optional structured attributes. * @param message The log message * @param attributes Optional key-value pairs for structured logging */ export declare function error(message: string, attributes?: Record<string, unknown>): void; /** * Logger interface representing the structured logging functionality */ export interface Logger { debug(message: string, attributes?: Record<string, unknown>): void; info(message: string, attributes?: Record<string, unknown>): void; warn(message: string, attributes?: Record<string, unknown>): void; error(message: string, attributes?: Record<string, unknown>): void; } export {}; //# sourceMappingURL=index.d.ts.map