# 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
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
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 |
A new logger instance labeled with the provided reason and id
# static benchmark(msg) → {void}
Delegates the benchmark logging to the global logger instance.
Logs a benchmark message.
Parameters:
| Name | Type | Description |
|---|---|---|
msg |
The message to be logged. |
void
# 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. |
void
# static error(msg, e) → {void}
Delegates the error logging to the global logger instance.
Logs an error message.
Parameters:
| Name | Type | Description |
|---|---|---|
msg |
The message to be logged. |
|
e |
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 |
A new logger instance for the specified object or context
# static get()
Returns the existing global logger or creates a new one if it doesn't exist.
Retrieves or creates the global logger instance.
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
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. |
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 |
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 |
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. |
void
# static theme(text, type, loggerLevel, templateopt) → {string}
Applies styling (colors, formatting) to text based on the theme configuration
Applies theme styling to text
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 |
The styled text
string
# static trace(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. |
void
# 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). |
void
# static warn(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. |
void