# new MiniLogger(contextopt, confopt, baseContextopt)
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 | Attributes | Default | Description |
|---|---|---|---|---|
context |
string
|
<optional> |
The context (typically class name) this logger is associated with. |
|
conf |
Partial.<LoggingConfig>
|
<optional> |
Optional configuration to override global settings. |
|
baseContext |
Array.<string>
|
<optional> |
[] | The base context for the logger. |
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
# action(action, codeopt, metaopt) → {void}
Action entries are a separate, more controlled channel from the rest of the Logger API - they carry no message, are not tied to any LogLevel, and always print regardless of the configured minimum level. The action name (plus its optional numeric code) is rendered where the level would otherwise appear, and the structured meta is always rendered too, regardless of the meta display setting. An entry's payload is exactly: the action string, an optional code, and meta - nothing else.
Logs an action: a discrete, named event carrying its own metadata rather than a severity level or a message.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
action |
string
|
The action name/identifier. |
|
code |
number
|
<optional> |
An optional numeric classification code for the action. |
meta |
LogMeta
|
<optional> |
Optional structured metadata, always rendered regardless of the |
void
# benchmark(msg, metaopt) → {void}
Logs a message at the benchmark level if the current verbosity setting allows it.
Logs a message at the benchmark level.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
msg |
StringLike
|
The message to be logged. |
|
meta |
object
|
<optional> |
Optional metadata to include with the entry. |
void
# clear() → {this}
Returns the same logger instance so more contexts can be chained afterwards.
Clears any contextual overrides applied by for.
The same logger instance.
this
# protected createLog(levelopt, message, erroropt) → {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
|
<optional> |
The log level for this message. Omitted ( |
message |
StringLike
|
Error
|
The message to log or an Error object. |
|
error |
Error
|
<optional> |
Optional error to extract stack trace to include in the log. |
A formatted log string with all components.
string
# critical(msg, eopt, metaopt) → {void}
Logs a message at the critical level for severe failures that need immediate attention.
Logs a message at the critical level.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
msg |
StringLike
|
Error
|
The message to be logged or an Error object. |
|
e |
Error
|
object
|
<optional> |
Optional error or metadata to include in the log. |
meta |
object
|
<optional> |
Optional metadata to include with the entry when an error is supplied. |
void
# debug(msg, metaopt) → {void}
Logs a message at the debug level for detailed troubleshooting information.
Logs a message at the debug level.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
msg |
StringLike
|
The message to be logged. |
|
meta |
object
|
<optional> |
Optional metadata to include with the entry. |
void
# error(msg, eopt, metaopt) → {void}
Logs a message at the error level for errors and exceptions.
Logs a message at the error level.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
msg |
StringLike
|
Error
|
The message to be logged or an Error object. |
|
e |
Error
|
object
|
<optional> |
Optional error or metadata to include in the log. |
meta |
object
|
<optional> |
Optional metadata to include with the entry when an error is supplied. |
void
# fatal(msg, eopt, metaopt) → {void}
Logs a message at the fatal level for unrecoverable failures.
Logs a message at the fatal level.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
msg |
StringLike
|
Error
|
The message to be logged or an Error object. |
|
e |
Error
|
object
|
<optional> |
Optional error or metadata to include in the log. |
meta |
object
|
<optional> |
Optional metadata to include with the entry when an error is supplied. |
void
# for(methodopt, configopt, …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
|
object
|
Partial.<LoggingConfig>
|
<optional> |
The method name, function, or configuration to create a logger for. |
config |
Partial.<LoggingConfig>
|
<optional> |
Optional configuration to override settings. |
args |
Array.<any>
|
<repeatable> |
Additional arguments to pass to the logger factory. |
A new logger instance for the specified method.
# info(msg, metaopt) → {void}
Logs a message at the info level for general application information.
Logs a message at the info level.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
msg |
StringLike
|
The message to be logged. |
|
meta |
object
|
<optional> |
Optional metadata to include with the entry. |
void
# protected log(level, msg, erroropt) → {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. |
|
error |
Error
|
<optional> |
Optional stack trace to include in the log. |
void
# protected methodFor(level)
Maps each LogLevel to the console method that should carry it (error levels to console.error, warn to console.warn, etc).
Resolves the console method used to emit a given log level.
Parameters:
| Name | Type | Description |
|---|---|---|
level |
LogLevel
|
The log level to resolve a console method for. |
The console method for that level.
# 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, metaopt) → {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. |
meta |
object
|
<optional> |
Optional metadata to include with the entry. |
void
# trace(msg, metaopt) → {void}
Logs a message at the trace level for tracing code execution.
Logs a message at the trace level.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
msg |
StringLike
|
The message to be logged. |
|
meta |
object
|
<optional> |
Optional metadata to include with the entry. |
void
# verbose(msg, verbosityopt, metaopt) → {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. |
meta |
object
|
<optional> |
Optional metadata to include with the entry. |
void
# warn(msg, metaopt) → {void}
Logs a message at the warning level for potential issues.
Logs a message at the warning level.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
msg |
StringLike
|
The message to be logged. |
|
meta |
object
|
<optional> |
Optional metadata to include with the entry. |
void
# protected write(method, formatted) → {void}
The single place every logging method funnels through to actually write output, so console access stays in one spot.
Emits an already-formatted log line.
Parameters:
| Name | Type | Description |
|---|---|---|
method |
The console method to invoke (e.g. |
|
formatted |
string
|
The fully formatted log line, as produced by |
void