Creates a new synchronous logger instance.
Optionaloptions: LoggerOptions = {}Configuration options
Configuration options for a MagicLogger instance. These settings control the logger's behavior, output format, identity, and destination.
Optionalcontext?: Record<string, unknown>Optional default context applied to all logs. Can include environment metadata, user data, etc. Individual log calls may override this.
OptionalfallbackToSync?: booleanFallback to synchronous logging when async buffers are full. Only applies when mode is 'async' or 'balanced'.
Optionalfile?: stringFile path for log output (SyncLogger only). When provided, logs will be written to this file synchronously.
OptionalforceFlush?: booleanForce flush to disk after each write (SyncLogger only). Uses fsync to ensure data is written to disk.
Optionalid?: stringUnique identifier for the logger instance. Used for filtering logs across services or systems.
OptionalidGenerator?: () => stringCustom ID generator function for log entries.
Optionallevel?: stringMinimum log level to output. Messages below this level will be filtered out.
OptionallogDir?: stringDirectory to store log files in (Node only).
OptionallogRetentionDays?: numberNumber of days to retain log files before pruning (Node only).
OptionalmaxStoredLogs?: numberMaximum number of log entries to keep in browser storage. Has no effect in Node.js environments.
Optionalmode?: "sync" | "async" | "auto" | "balanced"Logger performance mode configuration.
Optionalperformance?: "features" | "balanced" | "speed"Performance target hint for auto mode detection.
OptionalperformanceMode?: booleanEnable performance mode to disable styling for maximum throughput. When enabled, all styling is bypassed for 3x+ performance improvement.
OptionalprettyPrint?: "json" | "inspect"Pretty-printing mode for non-string variadic args. 'inspect' uses util.inspect in Node (with colors when enabled); 'json' uses JSON.stringify; default is 'inspect'.
OptionalprintMetaInDebug?: booleanWhen true, and verbose mode is enabled, append a compact [meta] summary of selected keys after the printed message. Meta remains structured for transports. Default: false
OptionalqueueManager?: QueueManagerOptions | QueueManagerQueue management configuration for handling backpressure. Can be a QueueManager instance or options to create one.
OptionalrateLimiter?: RateLimiterOptions | RateLimiterRate limiting configuration for log throttling. Can be a RateLimiter instance or options to create one.
Optionalredactor?: RedactorOptions | RedactorPII and sensitive data redaction configuration. Can be a Redactor instance or options to create one.
Optionalsampler?: SamplerOptions | SamplerStatistical sampling configuration for volume control. Can be a Sampler instance or options to create one.
OptionalstorageName?: stringName to use for browser storage (localStorage key or IndexedDB name). Has no effect in Node.js environments.
OptionalstoreInBrowser?: booleanWhether to store logs in browser storage when in browser environment. Has no effect in Node.js environments.
OptionalstrictLevels?: booleanEnforces strict log level behavior.
If true, unknown levels passed to .log() will throw.
If false, unknown levels are treated as custom and passed to .custom().
Optionaltags?: string[]Optional static tags applied to all logs from this logger. Helps group or filter logs by functional or organizational tag.
Optionaltheme?: string | ThemeDefinitionTheme used to style logger output. Can be a string (theme name from ThemeManager) or a full object.
OptionalthemeByTag?: Record<string, string>Optional mapping of tags to theme names. When provided, if a logger has any tag present in this map and no explicit theme is set, the mapped theme will be auto-applied. This enables brand/company-specific themes via tags.
Optionaltransports?: Transport[]Array of transports to use for logging.
OptionaluseColors?: booleanEnables or disables terminal or console color output.
OptionaluseConsole?: booleanWhether to use console transport by default. Set to false to disable automatic console output.
OptionaluseDefaultTransports?: booleanWhether to automatically create default transports.
OptionaluseLocalStorage?: booleanWhether to use localStorage (true) or IndexedDB (false) for browser storage. Has no effect in Node.js environments.
Optionalverbose?: booleanIf enabled, debug-level logs will be shown.
OptionalwriteToDisk?: booleanWrites logs to disk in timestamped .log files (Node only).
Ignored in browsers.
Gets the chainable style builder for formatting text.
The style builder instance
Prints text in a decorative box.
Text to display in box
Box formatting options
Closes file handles and performs cleanup.
Colors specific parts of a message based on a color map.
The message to log
Map of text patterns to color arrays
The styled message string
Resets a counter.
Counter label to reset
Logs a custom styled message with optional prefix. Supports arbitrary color combinations and custom prefixes.
Message to log
Array of color names to apply (default: ['white'])
Custom prefix for the message (default: 'LOG')
Logs a debug-level message synchronously.
The debug message to log
Optionalmeta: LogEntryMetaOptional metadata object
Logs an error-level message synchronously with optional Error object.
The error message
Optionalerror: Error | LogEntryMetaError object or metadata
Optionalmeta: LogEntryMetaAdditional metadata if error is an Error
Formats text using template literal syntax with embedded styles.
Template literal strings
Interpolated values
The formatted string with styles applied
Gets the number of writes to the file (for debugging).
Creates a log group (for API compatibility).
Group label
Ends a log group (for API compatibility).
Prints a formatted header with separators.
The header text to display
Optionalstyles: string[]Optional array of color names to apply
Logs an info-level message synchronously.
The message to log
Optionalmeta: LogEntryMetaOptional metadata object
Generic synchronous logging method with custom level.
The message to log
Optionallevel: string = 'info'The severity level
Optionalmeta: LogEntryMetaOptional metadata object
Displays a text-based progress bar.
Progress percentage (0-100)
Optionalwidth: number = 40Width of the progress bar in characters
OptionalfillChar: string = '█'Character for filled portion
OptionalemptyChar: string = '░'Character for empty portion
Prints a separator line.
Optionalchar: string = '-'Character to repeat for the separator
Optionallength: number = 60Length of the separator line
Logs a message with a predefined style preset.
Message to log
Style preset name
Logs a success-level message synchronously.
The success message to log
Optionalmeta: LogEntryMetaOptional metadata object
Displays data in a formatted table.
Array of objects to display
Table formatting options
Stops a timer and logs elapsed time.
Timer label to stop
Logs a warning-level message synchronously.
The warning message
Optionalmeta: LogEntryMetaOptional metadata
Synchronous logger with blocking I/O for guaranteed delivery.
All operations complete before returning, ensuring logs are written immediately. Perfect for security auditing, debugging, and crash-resilient logging at the cost of blocking application execution.
SyncLogger
Example: Basic usage
Example: Audit logging