UNPKG

@analog-tools/logger

Version:

Logging utility for AnalogJS applications

134 lines (133 loc) 5.12 kB
import { LogLevelEnum, LogStyling } from './logger.types'; import { StyleScheme, IconScheme } from './logger.config'; import { ILoggerStyleEngine, LoggerStyleEngineConfig, MetadataParseResult, StyleApplication } from './logger-style-engine.types'; /** * LoggerStyleEngine - Handles all styling, formatting, and color management for logger output * * This service is responsible for: * - ANSI color code management * - Message formatting with colors and prefixes * - Metadata-based styling application * - Icon resolution and validation * - Semantic style management * - Color application for log levels */ export declare class LoggerStyleEngine implements ILoggerStyleEngine { /** * Public method to resolve a style definition and return the ANSI color code (with caching) * @param style Style definition (semantic name or custom config) * @returns ANSI color code or undefined if invalid */ resolveStyle(style: StyleApplication, loggerName?: string, context?: string): string | undefined; /** * Cache for resolved style definitions (memoization) * Key: string for semantic style, object reference for custom style */ private styleCache; /** * Mark this service as injectable for @analog-tools/inject */ static INJECTABLE: boolean; private useColors; private globalStyles; private globalIcons; /** * Create a new LoggerStyleEngine * @param config Configuration for the style engine */ constructor(config?: LoggerStyleEngineConfig); /** * Enable or disable colored output * @param enabled Whether colors should be enabled */ setUseColors(enabled: boolean): void; /** * Check if colors are enabled * @returns Whether colors are enabled */ getUseColors(): boolean; /** * Update style and icon configuration * @param styles Partial style configuration to merge * @param icons Partial icon configuration to merge */ updateStyleConfig(styles: Partial<StyleScheme>, icons: Partial<IconScheme>): void; /** * Format a log message with color and proper prefix * @param level Log level for the message * @param message The message to format * @param loggerName The name of the logger * @param context Optional context for the logger * @param overrideColor Optional color override for the message * @returns Formatted message with color */ formatMessage(level: LogLevelEnum, message: string, loggerName: string, context?: string, overrideColor?: string): string; /** * Format message with metadata-based styling and icons * @param level Log level * @param message Message to format * @param loggerName The name of the logger * @param styling Optional metadata for styling * @param context Optional context for the logger * @returns Formatted message with styling and icons */ formatMessageWithMetadata(level: LogLevelEnum, message: string, loggerName: string, styling?: LogStyling, context?: string): string; /** * Parse metadata parameter to separate metadata from additional data * @param metadataOrData Could be LogStyling or additional data * @param data Additional data parameters * @returns Parsed metadata and remaining data */ parseMetadataParameter(metadataOrData?: LogStyling | unknown, data?: unknown[]): MetadataParseResult; /** * Get color for a specific log level * @param level The log level * @returns ANSI color code for the log level * @private */ private getColorForLevel; /** * Apply style configuration and return ANSI color code * @param style Style configuration (semantic name or custom config) * @param loggerName Logger name for error messages * @param context Optional context for error messages * @returns ANSI color code or undefined if invalid * @private */ private applyStyle; private isValidColor; private isValidIcon; private getStyleCacheValue; private setStyleCache; private logWarning; private constructStyleCode; /** * Get ANSI color code for semantic style names * @param styleName Semantic style name * @param loggerName Logger name for error messages * @param context Optional context for error messages * @returns ANSI color code or undefined if unknown * @private */ private getSemanticStyleColor; /** * Expose style cache for diagnostics/testing */ getStyleCache(): Map<string | object, string | undefined>; /** * Resolve icon to emoji character * @param icon Icon name or custom string * @param loggerName Logger name for error messages * @param context Optional context for error messages * @returns Emoji character * @private */ private resolveIcon; /** * Check if the provided icon is a valid emoji from our Icon type * @param icon Icon to check * @returns True if it's a valid emoji icon * @private */ private isEmojiIcon; }