Creates a new synchronous logger instance.
Optional
options: LoggerOptions = {}Configuration options
Configuration options for a MagicLogger instance. These settings control the logger's behavior, output format, identity, and destination.
Optional
context?: Record<string, unknown>Optional default context applied to all logs. Can include environment metadata, user data, etc. Individual log calls may override this.
Optional
fallbackToSync?: booleanFallback to synchronous logging when async buffers are full. Only applies when mode is 'async' or 'balanced'.
Optional
file?: stringFile path for log output (SyncLogger only). When provided, logs will be written to this file synchronously.
Optional
forceFlush?: booleanForce flush to disk after each write (SyncLogger only). Uses fsync to ensure data is written to disk.
Optional
id?: stringUnique identifier for the logger instance. Used for filtering logs across services or systems.
Optional
idGenerator?: () => stringCustom ID generator function for log entries.
Optional
level?: stringMinimum log level to output. Messages below this level will be filtered out.
Optional
logDir?: stringDirectory to store log files in (Node only).
Optional
logRetentionDays?: numberNumber of days to retain log files before pruning (Node only).
Optional
maxStoredLogs?: numberMaximum number of log entries to keep in browser storage. Has no effect in Node.js environments.
Optional
mode?: "sync" | "async" | "auto" | "balanced"Logger performance mode configuration.
Optional
performance?: "features" | "balanced" | "speed"Performance target hint for auto mode detection.
Optional
performanceMode?: booleanEnable performance mode to disable styling for maximum throughput. When enabled, all styling is bypassed for 3x+ performance improvement.
Optional
prettyPrint?: "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'.
Optional
printMetaInDebug?: 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
Optional
queueManager?: QueueManagerOptions | QueueManagerQueue management configuration for handling backpressure. Can be a QueueManager instance or options to create one.
Optional
rateLimiter?: RateLimiterOptions | RateLimiterRate limiting configuration for log throttling. Can be a RateLimiter instance or options to create one.
Optional
redactor?: RedactorOptions | RedactorPII and sensitive data redaction configuration. Can be a Redactor instance or options to create one.
Optional
sampler?: SamplerOptions | SamplerStatistical sampling configuration for volume control. Can be a Sampler instance or options to create one.
Optional
storageName?: stringName to use for browser storage (localStorage key or IndexedDB name). Has no effect in Node.js environments.
Optional
storeInBrowser?: booleanWhether to store logs in browser storage when in browser environment. Has no effect in Node.js environments.
Optional
strictLevels?: 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()
.
Optional
tags?: string[]Optional static tags applied to all logs from this logger. Helps group or filter logs by functional or organizational tag.
Optional
theme?: string | ThemeDefinitionTheme used to style logger output. Can be a string (theme name from ThemeManager) or a full object.
Optional
themeByTag?: 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.
Optional
transports?: Transport[]Array of transports to use for logging.
Optional
useColors?: booleanEnables or disables terminal or console color output.
Optional
useConsole?: booleanWhether to use console transport by default. Set to false to disable automatic console output.
Optional
useDefaultTransports?: booleanWhether to automatically create default transports.
Optional
useLocalStorage?: booleanWhether to use localStorage (true) or IndexedDB (false) for browser storage. Has no effect in Node.js environments.
Optional
verbose?: booleanIf enabled, debug-level logs will be shown.
Optional
writeToDisk?: 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
Optional
meta: LogEntryMetaOptional metadata object
Logs an error-level message synchronously with optional Error object.
The error message
Optional
error: Error | LogEntryMetaError object or metadata
Optional
meta: 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
Optional
styles: string[]Optional array of color names to apply
Logs an info-level message synchronously.
The message to log
Optional
meta: LogEntryMetaOptional metadata object
Generic synchronous logging method with custom level.
The message to log
Optional
level: string = 'info'The severity level
Optional
meta: LogEntryMetaOptional metadata object
Displays a text-based progress bar.
Progress percentage (0-100)
Optional
width: number = 40Width of the progress bar in characters
Optional
fillChar: string = '█'Character for filled portion
Optional
emptyChar: string = '░'Character for empty portion
Prints a separator line.
Optional
char: string = '-'Character to repeat for the separator
Optional
length: 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
Optional
meta: 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
Optional
meta: 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