# new MiniLogger(context, conf)
MiniLogger is a lightweight logging class that implements the Logger interface. It provides basic logging functionality with support for different log levels, verbosity, context-aware logging, and customizable formatting.
A minimal logger implementation.
Parameters:
Name | Type | Description |
---|---|---|
context |
string
|
The context (typically class name) this logger is associated with |
conf |
Partial.<LoggingConfig>
|
Optional configuration to override global settings |
Example
// Create a new logger for a class
const logger = new MiniLogger('MyClass');
// Log messages at different levels
logger.info('This is an info message');
logger.debug('This is a debug message');
logger.error('Something went wrong');
// Create a child logger for a specific method
const methodLogger = logger.for('myMethod');
methodLogger.verbose('Detailed information', 2);
// Log with custom configuration
logger.for('specialMethod', { style: true }).info('Styled message');
Methods
# protected createLog(level, message, stackopt) → {string}
Generates a log string with timestamp, colored log level, context, and message
Creates a formatted log string
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
level |
LogLevel
|
The log level for this message |
|
message |
StringLike
|
Error
|
The message to log or an Error object |
|
stack |
string
|
<optional> |
Optional stack trace to include in the log |
A formatted log string with all components
string
# debug(msg) → {void}
Logs a message at the debug level for detailed troubleshooting information
Logs a message at the debug level
Parameters:
Name | Type | Description |
---|---|---|
msg |
StringLike
|
The message to be logged |
void
# error(msg) → {void}
Logs a message at the error level for errors and exceptions
Logs a message at the error level
Parameters:
Name | Type | Description |
---|---|---|
msg |
StringLike
|
Error
|
The message to be logged or an Error object |
void
# for(method, config, …args) → {Logger}
Returns a new logger instance with the current context extended by the specified method name
Creates a child logger for a specific method or context
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
method |
string
|
function
|
The method name or function to create a logger for |
|
config |
Partial.<LoggingConfig>
|
Optional configuration to override settings |
|
args |
any
|
<repeatable> |
Additional arguments to pass to the logger factory |
A new logger instance for the specified method
# info(msg) → {void}
Logs a message at the info level for general application information
Logs a message at the info level
Parameters:
Name | Type | Description |
---|---|---|
msg |
StringLike
|
The message to be logged |
void
# protected log(level, msg, stackopt) → {void}
Checks if the message should be logged based on the current log level, then uses the appropriate console method to output the formatted log
Logs a message with the specified log level
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
level |
LogLevel
|
The log level of the message |
|
msg |
StringLike
|
Error
|
The message to be logged or an Error object |
|
stack |
string
|
<optional> |
Optional stack trace to include in the log |
void
# setConfig(config) → {void}
Merges the provided configuration with the existing configuration
Updates the logger configuration
Parameters:
Name | Type | Description |
---|---|---|
config |
Partial.<LoggingConfig>
|
The configuration options to apply |
void
# silly(msg, verbosityopt) → {void}
Logs a message at the silly level if the current verbosity setting allows it
Logs a message at the silly level
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
msg |
StringLike
|
The message to be logged |
||
verbosity |
number
|
<optional> |
0 | The verbosity level of the message |
void
# verbose(msg, verbosityopt) → {void}
Logs a message at the verbose level if the current verbosity setting allows it
Logs a message at the verbose level
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
msg |
StringLike
|
The message to be logged |
||
verbosity |
number
|
<optional> |
0 | The verbosity level of the message |
void