# 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
# _config
Stores the global logging configuration including verbosity, log level, styling, and formatting settings
Configuration for the logging system
# _factory
A function that creates new Logger instances. By default, it creates a MiniLogger.
Factory function for creating logger instances
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 |
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. |
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. |
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 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