@analog-tools/logger
Version:
Logging utility for AnalogJS applications
173 lines (172 loc) • 6.64 kB
TypeScript
/**
* Enum for dreamy color names with ANSI codes for terminal
* Each color has 3 shades and a background variant
*/
export declare enum ColorEnum {
SkyBlue = "\u001B[94m",// Bright blue
OceanBlue = "\u001B[34m",// Standard blue
MidnightBlue = "\u001B[38;5;17m",// Deep blue (unique)
SkyBlueBg = "\u001B[104m",
OceanBlueBg = "\u001B[44m",
MidnightBlueBg = "\u001B[48;5;17m",
MintGreen = "\u001B[92m",// Bright green
ForestGreen = "\u001B[32m",// Standard green
EmeraldGreen = "\u001B[38;5;28m",// Deep green (unique)
MintGreenBg = "\u001B[102m",
ForestGreenBg = "\u001B[42m",
EmeraldGreenBg = "\u001B[48;5;28m",
LemonYellow = "\u001B[93m",// Bright yellow
SunflowerYellow = "\u001B[33m",// Standard yellow
GoldYellow = "\u001B[38;5;220m",// Gold (unique)
LemonYellowBg = "\u001B[103m",
SunflowerYellowBg = "\u001B[43m",
GoldYellowBg = "\u001B[48;5;220m",
RoseRed = "\u001B[91m",// Bright red
FireRed = "\u001B[31m",// Standard red
BurgundyRed = "\u001B[38;5;88m",// Deep red (unique)
RoseRedBg = "\u001B[101m",
FireRedBg = "\u001B[41m",
BurgundyRedBg = "\u001B[48;5;88m",
LavenderPurple = "\u001B[95m",// Bright purple
RoyalPurple = "\u001B[38;5;93m",// Medium purple (unique)
DeepPurple = "\u001B[38;5;54m",// Deep purple (unique)
LavenderPurpleBg = "\u001B[105m",
RoyalPurpleBg = "\u001B[48;5;93m",
DeepPurpleBg = "\u001B[48;5;54m",
PeachOrange = "\u001B[38;5;215m",// Light orange
TangerineOrange = "\u001B[38;5;208m",// Standard orange
AmberOrange = "\u001B[38;5;214m",// Deep orange
PeachOrangeBg = "\u001B[48;5;215m",
TangerineOrangeBg = "\u001B[48;5;208m",
AmberOrangeBg = "\u001B[48;5;214m",
SilverGray = "\u001B[37m",// Light gray
SlateGray = "\u001B[90m",// Medium gray
CharcoalGray = "\u001B[38;5;238m",// Dark gray (unique)
SilverGrayBg = "\u001B[47m",
SlateGrayBg = "\u001B[100m",
CharcoalGrayBg = "\u001B[48;5;238m",
PureBlack = "\u001B[30m",
PureWhite = "\u001B[97m",
PureBlackBg = "\u001B[40m",
PureWhiteBg = "\u001B[107m",
Cyan = "\u001B[36m",
Reset = "\u001B[0m",
Bold = "\u001B[1m",
Dim = "\u001B[2m",
Underline = "\u001B[4m",
Blink = "\u001B[5m",
Reverse = "\u001B[7m",
Hidden = "\u001B[8m"
}
/**
* Semantic style names for logger styling
*/
export type SemanticStyleName = 'highlight' | 'accent' | 'attention' | 'success' | 'warning' | 'error' | 'info' | 'debug';
/**
* Icon type for logger styling (all available emojis as string literals)
*/
export type Icon = '✅' | '⚠️' | '❌' | 'ℹ️' | '🐞' | '⭐️' | '🚀' | '🔥' | '✔️' | '✖️' | '❓' | '🔒' | '🔓' | '⏳' | '🕒' | '⬆️' | '⬇️' | '➡️' | '⬅️' | '📁' | '📄' | '👤' | '👥' | '✏️' | '➕' | '➖' | '🔔' | '⚡️' | '🎁' | '🐛' | '🌟' | '❤️' | '👀' | '⚙️' | '🔧' | '🔨' | '🔑' | '🎉' | '📝' | '🚨' | '📅' | '💡' | '🔍' | '🔗' | '🔖' | '📌' | '📎' | '✉️' | '📞' | '🌍' | '☁️' | '🌈' | '🌙' | '☀️' | '❄️' | '✨' | '🎵' | '📷' | '🎥' | '🎤' | '🔊' | '🔋' | '🗑️' | '💰' | '💳' | '🎂' | '🏅' | '🏆' | '👑' | '🛸' | '🛡️' | '🛑' | '▶️' | '⏸️' | '⏺️' | '⏪' | '⏩' | '🔁' | '🔀' | '🎲' | '🎈' | '🍪' | '☕️' | '🍵' | '🍺' | '🍷' | '🍕' | '🍔' | '🍟' | '🍎' | '🍌' | '🍒' | '🍋' | '🥕' | '🌽' | '🥦' | '🥚' | '🧀' | '🍞' | '🍰' | '🍦' | '🍫' | '🍿' | '🥓' | '🍤' | '🐟' | '🦀' | '🐙' | '🐋' | '🐬' | '🐧' | '🐸' | '🐢' | '🐍' | '🐉' | '🦄' | '🐱' | '🐶' | '🐭' | '🐰' | '🐻' | '🐼' | '🐨' | '🐯' | '🦁' | '🐒' | '🐘' | '🐎' | '🐄' | '🐖' | '🐑' | '🐔' | '🦆' | '🦢' | '🦉' | '🦅' | '🦜' | '🦚' | '🦩' | '🦋' | '🐝' | '🐜' | '🐞' | '🕷️' | '🦂' | '🐌' | '🪱' | '🐛' | '🦗' | '🦟' | '🪰' | '🪳' | '🪲';
/**
* LogStyling for visual styling and icons in log output
*/
export interface LogStyling {
style?: SemanticStyleName | {
color: ColorEnum;
bold?: boolean;
underline?: boolean;
};
icon?: Icon | string;
}
/**
* Valid log level strings
*/
export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal' | 'silent';
export declare enum LogLevelEnum {
trace = 0,
debug = 1,
info = 2,
warn = 3,
error = 4,
fatal = 5,
silent = 6
}
/**
* Contextual data for structured logging
*
* A plain object containing key-value pairs that provide
* additional context for log entries. Used to attach
* structured data to log messages for better debugging
* and monitoring.
*
* @example
* ```typescript
* const context: LogContext = {
* userId: '12345',
* operation: 'login',
* duration: 150,
* success: true
* };
*
* logger.error('Login failed', context);
* ```
*/
export interface LogContext {
[key: string]: unknown;
correlationId?: string;
userId?: string;
requestId?: string;
context?: Record<string, unknown>;
}
/**
* Type guard to check if a string is a valid log level
* @param level - The string to check
* @returns True if the string is a valid log level
*/
export declare function isValidLogLevel(level: string): level is LogLevel;
/**
* Configuration options for the LoggerService
*/
export interface LoggerConfig {
/**
* The log level to use
* @default 'info'
*/
level?: LogLevel;
/**
* The name of the logger to use in logs
* @default 'analog-tools'
*/
name?: string;
/**
* The contexts you don't want to log
*/
disabledContexts?: string[];
/**
* Whether to use colors in the console output
* @default true
*/
useColors?: boolean;
/**
* Global style configuration for semantic styles
*/
styles?: Partial<Record<SemanticStyleName, {
color: ColorEnum;
bold?: boolean;
underline?: boolean;
}>>;
/**
* Global icon configuration for semantic icons
*/
icons?: Partial<Record<'success' | 'warning' | 'error' | 'info' | 'debug', Icon>>;
/**
* Log deduplication configuration
*/
deduplication?: {
/** Whether deduplication is enabled (default: false) */
enabled: boolean;
/** Time window in milliseconds for batching messages (default: 5000) */
windowMs?: number;
/** Whether to flush immediately on critical levels (default: true) */
flushOnCritical?: boolean;
};
}