Constructor
new Logger(name, …args)
Constructs a Logger instance with the given name and optional additional prefixes.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
string | The main name or component for the logger prefix. | |
args |
string | boolean | null | undefined |
<repeatable> |
Additional prefix arguments. |
Properties:
Name | Type | Description |
---|---|---|
logPrefix |
string | The formatted prefix for all log messages from this logger. |
prefixes |
Array.<string> | The list of prefix strings used to build the logPrefix. |
Members
debug
console.debug() with the logger's prefix.
deep
Calls 'debug()' to log but only if FEDIALGO_DEEP_DEBUG env var is set.
info
console.info() with the logger's prefix.
log
console.log() with the logger's prefix.
trace
Calls 'debug()' to log but only if FEDIALGO_DEBUG env var is set.
warn
Call console.warn() with the logger's prefix. Checks for Error objs in args in the same way as `error()`.
warnWithoutTrace
Logs a warning message with a warn colored prefix (not a real warning level).
Methods
error(msg, …args) → {string}
Logs an error message or Error object to the console with the logger's prefix.
Checks whether any element of 'args' is an instance of Error for special handling.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
msg |
string | Error | The error message or Error object. | |
args |
any |
<repeatable> |
Additional arguments to log. |
Returns:
The error message string.
- Type
- string
line(msg) → {string}
Concatenates the logger's prefix and the given message.
Parameters:
Name | Type | Description |
---|---|---|
msg |
string | undefined | The message to prefix. |
Returns:
The prefixed log line.
- Type
- string
logAndThrowError(msg, …args)
Logs an error message and throws an Error with the stringified arguments and message.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
msg |
string | The error message. | |
args |
any |
<repeatable> |
Additional arguments to include in the error. |
Throws:
-
A new Error with the formatted message, optionally including the first Error argument.
- Type
- Error
logArrayReduction(before, after, objType, reasonopt)
Logs the reduction in size of an array (e.g., after filtering or deduplication).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
before |
Array.<T> | The array before reduction. | |
after |
Array.<T> | The array after reduction. | |
objType |
string | The type of object in the array. | |
reason |
string |
<optional> |
Optional reason for reduction. |
logSortedDict(msg, dict)
Logs a sorted dictionary of string-number pairs.
Parameters:
Name | Type | Description |
---|---|---|
msg |
string | The message to log before the dictionary. |
dict |
StringNumberDict | The dictionary to log. |
logTelemetry(msg, startedAt, …args)
Logs a message with the elapsed time since startedAt, optionally with additional labels/args.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
msg |
string | The message to log. | |
startedAt |
Date | The start time to compute elapsed time. | |
args |
any |
<repeatable> |
Additional arguments or labels. |
tagWithRandomString()
Adds a random string to the logger's prefix (useful for distinguishing logs in concurrent contexts).
tempLogger(arg1, …args) → {module:helpers/logger~Logger}
Returns a new Logger with additional prefix arguments appended to this.prefixes.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
arg1 |
string | The additional prefix. | |
args |
LoggerArg |
<repeatable> |
More prefix arguments. |
Returns:
A new Logger instance with the extended prefix.
- Type
- module:helpers/logger~Logger
(static) logBuilder(name, …prefixes) → {function}
Returns a function that builds Logger objects with the starting prefixes.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
string | The main name for the logger. | |
prefixes |
LoggerArg |
<repeatable> |
Additional prefixes. |
Returns:
A function that creates Logger instances with the given prefixes.
- Type
- function
(static) withParenthesizedName(name, parenthesized, …args) → {module:helpers/logger~Logger}
Alternate constructor; makes the first two arguments into a parenthesized bracketed string.
e.g. the prefix will be [name (parenthesized)].
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
string | The main name for the logger. | |
parenthesized |
string | The value to parenthesize in the prefix. | |
args |
string |
<repeatable> |
Additional prefix arguments. |
Returns:
A new Logger instance with the custom prefix.
- Type
- module:helpers/logger~Logger