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 363

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

# _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 436

# global

A singleton instance of Logger used for global logging.

The global logger instance.

View Source logging.ts, line 431

Methods

# static because(reason, idopt) → {Logger}

Utility to quickly create a logger labeled with a free-form reason and optional identifier so that ad-hoc operations can be traced without tying the logger to a class or method name.

Creates a logger for a specific reason or correlation context.

Parameters:
Name Type Attributes Description
reason string

A textual reason or context label for this logger instance.

id string <optional>

Optional identifier to help correlate related log entries.

View Source logging.ts, line 962

A new logger instance labeled with the provided reason and id.

Logger

# static benchmark(msg) → {void}

Delegates the benchmark logging to the global logger instance.

Logs a benchmark message.

Parameters:
Name Type Description
msg StringLike

The message to be logged.

View Source logging.ts, line 918

void

# static debug(msg) → {void}

Delegates the debug logging to the global logger instance.

Logs a debug message.

Parameters:
Name Type Description
msg StringLike

The message to be logged.

View Source logging.ts, line 910

void

# static error(msg, eopt) → {void}

Delegates the error logging to the global logger instance.

Logs an error message.

Parameters:
Name Type Attributes Description
msg StringLike | Error

The message to be logged.

e Error <optional>

Optional error to include in the log.

View Source logging.ts, line 943

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 953

A new logger instance for the specified object or context.

Logger

# static get() → {Logger}

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 877

The global Logger instance.

Logger

# 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 870

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 StringLike

The message to be logged.

View Source logging.ts, line 894

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 863

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 855

void

# static silly(msg) → {void}

Delegates the silly logging to the global logger instance.

Logs a silly message.

Parameters:
Name Type Description
msg StringLike

The message to be logged.

View Source logging.ts, line 926

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

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 997

The styled text.

string

# static trace(msg) → {void}

Delegates the trace logging to the global logger instance.

Logs a trace message.

Parameters:
Name Type Description
msg StringLike

The message to be logged.

View Source logging.ts, line 902

void

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

Delegates the verbose logging to the global logger instance.

Logs a verbose message.

Parameters:
Name Type Attributes Default Description
msg StringLike

The message to be logged.

verbosity number <optional>
0

The verbosity level of the message.

View Source logging.ts, line 886

void

# static warn(msg) → {void}

Delegates the warning logging to the global logger instance.

Logs a warning message.

Parameters:
Name Type Description
msg StringLike

The message to be logged.

View Source logging.ts, line 934

void