Skip to content

Logging

Logging utilities for debugging

← Back to @blac/core

Quick Reference

Interfaces: LogConfig, LogEntry

Functions: configureLogger, createLogger, debug, error, info, warn

Enum: LogLevel

Interfaces

LogConfig

Configuration for the logger

typescript
export interface LogConfig
PropertyTypeDescription
enabledbooleanWhether logging is enabled
levelLogLevelMinimum log level to output
output(entry: LogEntry) => voidFunction called to output log entries

LogEntry

Structure of a log entry passed to output handlers

typescript
export interface LogEntry
PropertyTypeDescription
contextstringContext identifier (typically component or module name)
data (optional)anyOptional structured data
levelstringLog level as string (DEBUG, INFO, WARN, ERROR)
messagestringLog message
timestampnumberUnix timestamp in milliseconds

Functions

configureLogger

Configuration function that recreates the default logger

typescript
export declare function configureLogger(opts: Partial<LogConfig>): void;
ParameterTypeDescription
optsPartial<LogConfig>Partial logger configuration

Examples:

ts
configureLogger({ enabled: true, level: LogLevel.DEBUG });

createLogger

Creates a logger instance with given configuration

typescript
export declare function createLogger(config: LogConfig): {
    debug: (context: string, message: string, data?: any) => void;
    info: (context: string, message: string, data?: any) => void;
    warn: (context: string, message: string, data?: any) => void;
    error: (context: string, message: string, data?: any) => void;
    configure: (opts: Partial<LogConfig>) => void;
};
ParameterTypeDescription
configLogConfigLogger configuration

Returns: Logger instance with debug, info, warn, error, and configure methods

Examples:

ts
const logger = createLogger({
  enabled: true,
  level: LogLevel.DEBUG,
  output: (entry) => console.log(JSON.stringify(entry))
});
logger.debug('MyComponent', 'Rendering', { props: { foo: 'bar' } });

debug

Log a debug message (tree-shakeable export)

typescript
debug: (context: string, message: string, data?: any) => void
ParameterTypeDescription
contextstringContext identifier (module or component name)
messagestringLog message
dataanyOptional structured data

error

Log an error message (tree-shakeable export)

typescript
error: (context: string, message: string, data?: any) => void
ParameterTypeDescription
contextstringContext identifier (module or component name)
messagestringLog message
dataanyOptional structured data

info

Log an info message (tree-shakeable export)

typescript
info: (context: string, message: string, data?: any) => void
ParameterTypeDescription
contextstringContext identifier (module or component name)
messagestringLog message
dataanyOptional structured data

warn

Log a warning message (tree-shakeable export)

typescript
warn: (context: string, message: string, data?: any) => void
ParameterTypeDescription
contextstringContext identifier (module or component name)
messagestringLog message
dataanyOptional structured data

Enums

LogLevel

Log severity levels (lower number = higher severity)

MemberValueDescription
DEBUG3Detailed debugging information
ERROR0Critical errors that may cause application failure
INFO2Informational messages about application state
WARN1Warning conditions that should be addressed

Released under the MIT License.