Class

Logging

Logging()

Constructor

# new Logging()

The Logging class provides a centralized logging mechanism with support for different log levels, verbosity, and styling. It uses a singleton pattern to maintain a global logger instance and allows creating specific loggers for different classes and methods.

A static class for managing logging operations

classDiagram class Logger { <> +for(method, config, ...args) +silly(msg, verbosity) +verbose(msg, verbosity) +info(msg) +debug(msg) +error(msg) +setConfig(config) } class Logging { -global: Logger -_factory: LoggerFactory -_config: LoggingConfig +setFactory(factory) +setConfig(config) +getConfig() +get() +verbose(msg, verbosity) +info(msg) +debug(msg) +silly(msg) +error(msg) +for(object, config, ...args) +because(reason, id) +theme(text, type, loggerLevel, template) } class MiniLogger { +constructor(context, conf?) } Logging ..> Logger : creates Logging ..> MiniLogger : creates by default

View Source logging.ts, line 212

Example
// Set global configuration
Logging.setConfig({ level: LogLevel.debug, style: true });

// Get a logger for a specific class
const logger = Logging.for('MyClass');

// Log messages at different levels
logger.info('Application started');
logger.debug('Processing data...');

// Log with context
const methodLogger = Logging.for('MyClass.myMethod');
methodLogger.verbose('Detailed operation information', 1);

// Log errors
try {
  // some operation
} catch (error) {
  logger.error(error);
}

Members

# _config

Stores the global logging configuration including verbosity, log level, styling, and formatting settings

Configuration for the logging system

View Source logging.ts, line 294

# _factory

A function that creates new Logger instances. By default, it creates a MiniLogger.

Factory function for creating logger instances

View Source logging.ts, line 287

# global

A singleton instance of Logger used for global logging

The global logger instance

View Source logging.ts, line 282

Methods

# static because(reason, id)

This static method creates a new logger instance using the factory function, based on a given reason or context.

Creates a logger for a specific reason or context.

Parameters:
Name Type Description
reason

A string describing the reason or context for creating this logger.

id

View Source logging.ts, line 722

A new VerbosityLogger or ClassLogger instance.

# static debug(msg) → {void}

Delegates the debug logging to the global logger instance.

Logs a debug message.

Parameters:
Name Type Description
msg

The message to be logged.

View Source logging.ts, line 682

void

# static error(msg) → {void}

Delegates the error logging to the global logger instance.

Logs an error message.

Parameters:
Name Type Description
msg

The message to be logged.

View Source logging.ts, line 700

void

# static for(object, configopt, …args) → {Logger}

Creates a new logger instance for the given object or context using the factory function

Creates a logger for a specific object or context

Parameters:
Name Type Attributes Description
object LoggingContext

The object, class, or context to create a logger for

config Partial.<LoggingConfig> <optional>

Optional configuration to override global settings

args any <repeatable>

Additional arguments to pass to the logger factory

View Source logging.ts, line 710

A new logger instance for the specified object or context

Logger

# static get()

Returns the existing global logger or creates a new one if it doesn't exist.

Retrieves or creates the global logger instance.

View Source logging.ts, line 654

The global VerbosityLogger instance.

# static getConfig() → {LoggingConfig}

Returns a copy of the current global logging configuration

Gets a copy of the current global logging configuration

View Source logging.ts, line 646

A copy of the current configuration

LoggingConfig

# static info(msg) → {void}

Delegates the info logging to the global logger instance.

Logs an info message.

Parameters:
Name Type Description
msg

The message to be logged.

View Source logging.ts, line 673

void

# static setConfig(config) → {void}

Allows updating the global logging configuration with new settings

Updates the global logging configuration

Parameters:
Name Type Description
config Partial.<LoggingConfig>

The configuration options to apply

View Source logging.ts, line 639

void

# static setFactory(factory) → {void}

Allows customizing how logger instances are created

Sets the factory function for creating logger instances

Parameters:
Name Type Description
factory LoggerFactory

The factory function to use for creating loggers

View Source logging.ts, line 631

void

# static silly(msg) → {void}

Delegates the debug logging to the global logger instance.

Logs a silly message.

Parameters:
Name Type Description
msg

The message to be logged.

View Source logging.ts, line 691

void

# static theme(text, type, loggerLevel, templateopt) → {string}

Applies styling (colors, formatting) to text based on the theme configuration

Applies theme styling to text

sequenceDiagram participant Caller participant Theme as Logging.theme participant Apply as apply function participant Style as styled-string-builder Caller->>Theme: theme(text, type, loggerLevel) Theme->>Theme: Check if styling is enabled alt styling disabled Theme-->>Caller: return original text else styling enabled Theme->>Theme: Get theme for type alt theme not found Theme-->>Caller: return original text else theme found Theme->>Theme: Determine actual theme based on log level Theme->>Apply: Apply each style property Apply->>Style: Apply colors and formatting Style-->>Apply: Return styled text Apply-->>Theme: Return styled text Theme-->>Caller: Return final styled text end end
Parameters:
Name Type Attributes Default Description
text string

The text to style

type string

The type of element to style (e.g., "class", "message", "logLevel")

loggerLevel LogLevel

The log level to use for styling

template Theme <optional>
DefaultTheme

The theme to use for styling

View Source logging.ts, line 757

The styled text

string

# static verbose(msg, verbosity) → {void}

Delegates the verbose logging to the global logger instance.

Logs a verbose message.

Parameters:
Name Type Description
msg

The message to be logged.

verbosity

The verbosity level of the message (default: 0).

View Source logging.ts, line 664

void