Comprehensive logging toolkit for browser and Node environments.
Interfaces
- Impersonatable
Declares a
formethod that returns another instance ofTHISusing the provided arguments, enabling chained logger customization.- Logger
Declares severity-specific log methods, configuration overrides, and factory helpers used throughout the logging toolkit.
- LoggingFilter
Allows custom pre-processing of log entries before they are formatted or emitted.
- Theme
Specifies styling for each console log element and supports overrides based on
LogLevelvalues.- ThemeOption
Configures foreground and background colors as well as additional style directives for styled console output.
Members
string
# static constant BrowserEnvKey
Enables the logging environment helpers to locate serialized environment configuration on globalThis.
Global key used to store environment variables in browser contexts.
Array.<string>
# static constant DefaultPlaceholderWrappers
Provides wrapper strings applied when interpolating messages with patchPlaceholders.
Default prefix and suffix used for template placeholders.
Theme
# static constant DefaultTheme
Defines the default color and style settings for various components of log messages.
Default theme for styling log output.
Properties:
| Name | Type | Description |
|---|---|---|
class |
Object
|
Styling for class names. |
fg |
number
|
Foreground color code for class names (34). |
id |
Object
|
Styling for identifiers. |
fg |
number
|
Foreground color code for identifiers (36). |
stack |
Object
|
Styling for stack traces (empty object). |
timestamp |
Object
|
Styling for timestamps (empty object). |
message |
Object
|
Styling for different types of messages. |
error |
Object
|
Styling for error messages. |
error.fg |
number
|
Foreground color code for error messages (31). |
method |
Object
|
Styling for method names (empty object). |
logLevel |
Object
|
Styling for different log levels. |
error |
Object
|
Styling for error level logs. |
error.fg |
number
|
Foreground color code for error level logs (31). |
error.style |
Array.<string>
|
Style attributes for error level logs (["bold"]). |
info |
Object
|
Styling for info level logs (empty object). |
verbose |
Object
|
Styling for verbose level logs (empty object). |
debug |
Object
|
Styling for debug level logs. |
debug.fg |
number
|
Foreground color code for debug level logs (33). |
string
# static constant ENV_PATH_DELIMITER
Joins parent and child keys when mapping object paths to ENV strings.
Delimiter used for composing nested environment variable names.
# static constant LoggedEnvironment
Combines DefaultLoggingConfig with runtime environment variables to provide consistent logging defaults across platforms.
Singleton environment instance seeded with default logging configuration.
NumericLogLevelsShape
# static constant NumericLogLevels
Provides a numeric representation of log levels for comparison and filtering.
Numeric values associated with log levels.
string
# static constant PACKAGE_NAME
Stores the package version for diagnostics and compatibility checks.
Current package version string.
string
# static constant VERSION
Stores the package version for diagnostics and compatibility checks.
Current package version string.
LoggerFactory
# static constant WinstonFactory
A LoggerFactory implementation that creates WinstonLogger instances
Factory function for creating Winston loggers
string
# static readonly exports.LogLevel
Defines different levels of logging for the application.
Enum for log levels.
string
# static exports.LoggingMode
Defines different output formats for log messages.
Enum for logging output modes.
Methods
# static escapeRegExp(string) → {string}
Adds backslashes before characters that have special meaning in regular expressions, allowing the string to be used as a literal match in a RegExp.
Escapes special characters in a string for use in a regular expression.
Parameters:
| Name | Type | Description |
|---|---|---|
string |
string
|
The string to escape for regular expression use. |
The escaped string safe for use in regular expressions.
string
# static formatMs(ms) → {string}
Breaks the duration into hours, minutes, seconds, and milliseconds, returning a zero-padded string.
Formats milliseconds into hh:mm:ss.mmm.
Parameters:
| Name | Type | Description |
|---|---|---|
ms |
number
|
Milliseconds to format. |
Formatted duration string.
string
# static isBrowser() → {boolean}
Checks if the code is running in a browser environment.
Determines if the current environment is a browser by checking the prototype chain of the global object.
True if the environment is a browser, false otherwise.
boolean
# static padEnd(str, length, charopt) → {string}
Extends the input string to a specified length by adding a padding character to the end. If the input string is already longer than the specified length, it is returned unchanged.
Pads the end of a string with a specified character.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
str |
string
|
The input string to be padded. |
||
length |
number
|
The desired total length of the resulting string. |
||
char |
string
|
<optional> |
" " | The character to use for padding. Defaults to a space. |
If the padding character is not exactly one character long.
Error
The padded string.
string
# static patchPlaceholders(input, values, prefix, suffix, flags) → {string}
Interpolates a string by replacing placeholders of the form ${variableName} with corresponding values from the provided object. If a placeholder doesn't have a corresponding value, it is left unchanged in the string.
Replaces placeholders in a string with provided values.
Parameters:
| Name | Type | Description |
|---|---|---|
input |
string
|
The input string containing placeholders to be replaced. |
values |
Record.<string, (number|string)>
|
An object containing key-value pairs for replacement. |
prefix |
||
suffix |
||
flags |
The interpolated string with placeholders replaced by their corresponding values.
string
# static patchString(input, values, flagsopt) → {string}
Iterates through a set of key-value pairs and replaces all occurrences of each key in the input string with its corresponding value. Supports regular expression flags for customized replacement.
Replaces occurrences of keys with their corresponding values in a string.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
input |
string
|
The input string in which replacements will be made. |
||
values |
Record.<string, (number|string)>
|
An object containing key-value pairs for replacement. |
||
flags |
string
|
<optional> |
"g" | Regular expression flags to control the replacement behavior. |
The string with all specified replacements applied.
string
# static sf(string, argsopt) → {string}
Util function to provide string format functionality similar to C#'s string.format
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
string |
string
|
||
args |
Array.<(string|number)>
|
Record.<string, any>
|
<optional> |
replacements made by order of appearance (replacement0 wil replace {0} and so on) |
formatted string
string
# static stringFormat()
Util function to provide string format functionality similar to C#'s string.format
- Deprecated:
- Yes
- See:
-
- sf
# static toCamelCase(text) → {string}
Transforms the input string into camelCase format, where words are joined without spaces and each word after the first starts with a capital letter.
Converts a string to camelCase.
Parameters:
| Name | Type | Description |
|---|---|---|
text |
string
|
The input string to be converted. |
The input string converted to camelCase.
string
# static toENVFormat(text) → {string}
Transforms the input string into uppercase with words separated by underscores, typically used for environment variable names.
Converts a string to ENVIRONMENT_VARIABLE format.
Parameters:
| Name | Type | Description |
|---|---|---|
text |
string
|
The input string to be converted. |
The input string converted to ENVIRONMENT_VARIABLE format.
string
# static toKebabCase(text) → {string}
Transforms the input string into lowercase with words separated by hyphens.
Converts a string to kebab-case.
Parameters:
| Name | Type | Description |
|---|---|---|
text |
string
|
The input string to be converted. |
The input string converted to kebab-case.
string
# static toPascalCase(text) → {string}
Transforms the input string into PascalCase format, where words are joined without spaces and each word starts with a capital letter.
Converts a string to PascalCase.
Parameters:
| Name | Type | Description |
|---|---|---|
text |
string
|
The input string to be converted. |
The input string converted to PascalCase.
string
# static toSnakeCase(text) → {string}
Transforms the input string into lowercase with words separated by underscores.
Converts a string to snake_case.
Parameters:
| Name | Type | Description |
|---|---|---|
text |
string
|
The input string to be converted. |
The input string converted to snake_case.
string
Type Definitions
# AnyFunction(args)
Covers variadic functions whose arguments and return types are not constrained, enabling the logging layer to accept any callable.
Generic function signature for loosely typed callbacks.
Parameters:
| Name | Type | Description |
|---|---|---|
args |
Array
|
any
# Class
Describes a constructor that produces instances of type T, allowing APIs to accept class references for context-aware logging.
Constructable class type.
Properties:
| Name | Type | Description |
|---|---|---|
...args: |
T
|
any[] |
LoggingConfig
# DefaultLoggingConfig
Defines the default settings for the logging system, including verbosity, log level, styling, and timestamp format.
Default configuration for logging.
Properties:
| Name | Type | Description |
|---|---|---|
verbose |
number
|
Verbosity level (0). |
level |
LogLevel
|
Default log level (LogLevel.info). |
logLevel |
boolean
|
Whether to display log level in output (true). |
mode |
LoggingMode
|
Output format mode (LoggingMode.RAW). |
style |
boolean
|
Whether to apply styling to log output (false). |
separator |
string
|
Separator between log components (" - "). |
timestamp |
boolean
|
Whether to include timestamps in log messages (true). |
timestampFormat |
string
|
Format for timestamps ("HH:mm:ss.SSS"). |
context |
boolean
|
Whether to include context information in log messages (true). |
theme |
Theme
|
The theme to use for styling log messages (DefaultTheme). |
# EnvironmentFactory(args)
Describes factories that construct Environment derivatives with custom initialization.
Factory type for creating Environment instances.
Parameters:
| Name | Type | Description |
|---|---|---|
args |
Array
|
Object
# Lap
Captures the lap index, optional label, elapsed milliseconds for the lap, and cumulative elapsed time since the stopwatch started.
Snapshot of a recorded lap interval.
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
index |
number
|
Zero-based lap order. |
|
label |
string
|
<optional> |
Optional label describing the lap. |
ms |
number
|
Duration of the lap in milliseconds. |
|
totalMs |
number
|
Total elapsed time when the lap was recorded. |
|
index |
number
|
||
label |
string
|
<optional> |
|
ms |
number
|
Duration of this lap in milliseconds |
|
totalMs |
number
|
Cumulative time up to this lap in milliseconds |
# LoggerFactory(object, configopt, args)
Allows consumers to override logger construction with custom implementations.
Factory signature for creating logger instances.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
object |
string
|
||
config |
Partial.<LoggingConfig>
|
<optional> |
|
args |
Array
|
Object
# LoggingConfig
Defines the log level and verbosity for logging.
Configuration for logging.
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
level |
LogLevel
|
The logging level. |
|
logLevel |
boolean
|
<optional> |
Whether to display log level in output. |
verbose |
number
|
The verbosity level. |
|
mode |
LoggingMode
|
<optional> |
Output format mode. |
contextSeparator |
string
|
Separator between context entries. |
|
separator |
string
|
Separator between log components. |
|
style |
boolean
|
<optional> |
Whether to apply styling to log output. |
timestamp |
boolean
|
<optional> |
Whether to include timestamps in log messages. |
timestampFormat |
string
|
<optional> |
Format for timestamps. |
context |
boolean
|
<optional> |
Whether to include context information in log messages. |
theme |
Theme
|
<optional> |
The theme to use for styling log messages. |
correlationId |
string
|
number
|
<optional> |
Correlation ID for tracking related log messages. |
app |
string
|
<optional> |
|
env |
"development"
|
"production"
|
"test"
|
"staging"
|
string
|
||
level |
LogLevel
|
||
logLevel |
boolean
|
<optional> |
|
verbose |
number
|
||
contextSeparator |
string
|
||
separator |
string
|
||
style |
boolean
|
<optional> |
|
timestamp |
boolean
|
<optional> |
|
timestampFormat |
string
|
<optional> |
|
context |
boolean
|
<optional> |
|
theme |
Theme
|
<optional> |
|
format |
LoggingMode
|
||
pattern |
string
|
||
correlationId |
string
|
number
|
<optional> |
|
filters |
Array
|
Array
|
<optional> |
# LoggingContext()
Allows the logging system to resolve context names from strings, constructors, or functions.
Context descriptor accepted when requesting a logger instance.
Object
# NumericLogLevelsShape
Provides a numeric representation of log levels for comparison and filtering.
Numeric values associated with log levels.
Properties:
| Name | Type | Description |
|---|---|---|
benchmark |
number
|
Numeric value for benchmark level (0). |
error |
number
|
Numeric value for error level (2). |
info |
number
|
Numeric value for info level (4). |
verbose |
number
|
Numeric value for verbose level (6). |
debug |
number
|
Numeric value for debug level (7). |
silly |
number
|
Numeric value for silly level (9). |
# ReplacementFunction(substring, args)
Receives the matched substring and additional capture arguments, returning the replacement text that will be injected into the log message.
Replacement callback used to transform RegExp matches.
Parameters:
| Name | Type | Description |
|---|---|---|
substring |
string
|
|
args |
Array
|
string
|
Object
# StringLike
Represents either a literal string or an object exposing a toString() method, allowing lazy stringification of complex payloads.
String-compatible value accepted by the logging APIs.
Properties:
| Name | Type | Description |
|---|---|---|
toString |
function
|