log.ts

Declarations
#

6 declarations

view source

log_level_parse
#

log.ts view source

(value: string | undefined): LogLevel | undefined

Parses and validates a log level string.

value

The value to parse as a log level

type string | undefined

returns

LogLevel | undefined

The validated log level, or undefined if value is undefined

throws

  • Error - if value is provided but invalid

log_level_to_number
#

log.ts view source

(level: LogLevel): number

Converts a log level to its numeric value for comparison. Higher numbers indicate more verbose logging.

level

The log level to convert

returns

number

Numeric value (0-4)

LogConsole
#

log.ts view source

LogConsole

Console interface subset used by Logger for output. Allows custom console implementations for testing.

Logger
#

log.ts view source

Simple, flexible logger with support for child loggers and automatic context.

Features: - Instance-based configuration (no global state) - Child loggers with automatic label concatenation - Parent chain inheritance for level, console, and colors - Respects NO_COLOR environment variable

examples

Example 1

label

type string

readonly

parent

type Logger

readonly

constructor

Creates a new Logger instance.

type new (label?: string | undefined, options?: LoggerOptions): Logger

label?

Optional label for this logger. Can be undefined for no label, or an empty string '' which is functionally equivalent (both produce no brackets in output). Note: Empty strings are only allowed for root loggers - child loggers cannot have empty labels.

type string | undefined
optional
options

Optional configuration for level, colors, and console

default {}

clear_level_override

Clears the level override for this logger, restoring inheritance from parent. After calling this, the logger will dynamically inherit the level from its parent (or use the default level if it has no parent).

type (): void

returns void

clear_colors_override

Clears the colors override for this logger, restoring inheritance from parent. After calling this, the logger will dynamically inherit colors from its parent (or use the default colors behavior if it has no parent).

type (): void

returns void

clear_console_override

Clears the console override for this logger, restoring inheritance from parent. After calling this, the logger will dynamically inherit the console from its parent (or use the global console if it has no parent).

type (): void

returns void

child

Creates a child logger with automatic label concatenation. Children inherit parent configuration unless overridden.

type (label: string, options?: LoggerOptions): Logger

label

Child label (will be concatenated with parent label using :). Cannot be an empty string - empty labels would result in confusing output like parent: with a trailing colon. Use undefined or '' only for root loggers.

type string
options

Optional configuration overrides

default {}
returns Logger

New Logger instance with concatenated label

throws
  • Error - if label is an empty string

error

Logs an error message with 🞩error🞩 prefix. Only outputs if current level is error or higher.

type (...args: unknown[]): void

args
type unknown[]
returns void

warn

Logs a warning message with ⚑warn⚑ prefix. Only outputs if current level is warn or higher.

type (...args: unknown[]): void

args
type unknown[]
returns void

info

Logs an informational message. Unlike error/warn/debug, info has no character prefix - only the label is shown. This keeps standard output clean since info is the default log level. Only outputs if current level is info or higher.

type (...args: unknown[]): void

args
type unknown[]
returns void

debug

Logs a debug message with ┆debug┆ prefix. Only outputs if current level is debug.

type (...args: unknown[]): void

args
type unknown[]
returns void

raw

Logs raw output without any prefix, formatting, or level filtering. Bypasses the logger's level checking, prefix formatting, and color application entirely. Useful for outputting structured data or when you need full control over formatting.

Note: This method ignores the configured log level - it always outputs regardless of whether the logger is set to 'off' or any other level.

type (...args: unknown[]): void

args

Values to log directly to console

type unknown[]
returns void

LoggerOptions
#

log.ts view source

LoggerOptions

level

Log level for this logger instance. Inherits from parent or defaults to 'info'.

console

Console interface for output. Inherits from parent or defaults to global console. Useful for testing.

colors

Whether to use colors in output. Inherits from parent or defaults to enabled (unless NO_COLOR env var is set).

type boolean

LogLevel
#

log.ts view source

LogLevel

Log level hierarchy from least to most verbose. - 'off': No logging - 'error': Only errors - 'warn': Errors and warnings - 'info': Errors, warnings, and info (default) - 'debug': All messages including debug

Imported by
#