A comprehensive and versatile logging toolkit for both browser and Node.js environments.
Interfaces
- Impersonatable
Declares a
formethod that returns another instance ofTHISusing the provided arguments. This enables chained logger customization.- Logger
This interface declares severity-specific log methods, configuration overrides, and factory helpers that are used throughout the logging toolkit.
- LoggingFilter
This allows for custom pre-processing of log entries before they are formatted or emitted.
- Theme
This interface specifies the styling for each console log element and supports overrides based on
LogLevelvalues.- ThemeOption
This interface configures the foreground and background colors, as well as additional style directives for styled console output.
Members
string
# static constant BrowserEnvKey
This enables the logging environment helpers to locate serialized environment configuration on globalThis.
The global key that is used to store environment variables in browser contexts.
LoggingConfig
# static constant DefaultLoggingConfig
Defines the default settings for the logging system, including verbosity, log level, styling, and timestamp format.
The default configuration for logging.
Array.<string>
# static constant DefaultPlaceholderWrappers
This provides wrapper strings that are applied when interpolating messages with patchPlaceholders.
The default prefix and suffix that are used for template placeholders.
Theme
# static constant DefaultTheme
Defines the default color and style settings for various components of log messages.
The default theme for styling log output.
string
# static constant ENV_PATH_DELIMITER
This joins parent and child keys when mapping object paths to ENV strings.
The delimiter that is used for composing nested environment variable names.
AccumulatedEnvironment.<any>
# static constant LoggedEnvironment
This constant combines DefaultLoggingConfig with runtime environment variables to provide consistent logging defaults across platforms.
A singleton environment instance that is seeded with the default logging configuration.
NumericLogLevelsShape
# static constant NumericLogLevels
This provides a numeric representation of log levels for comparison and filtering.
The numeric values that are associated with log levels.
string
# static constant PACKAGE_NAME
Stores the package version for diagnostics and compatibility checks.
Current package version string.
LoggerFactory
# static constant PinoFactory
This factory function creates a new PinoLogger instance, and can optionally accept a pre-existing Pino logger instance.
A factory for creating PinoLogger instances.
string
# static constant VERSION
Stores the package version for diagnostics and compatibility checks.
Current package version string.
# static constant WinstonFactory
This is a LoggerFactory implementation that creates WinstonLogger instances.
A factory function for creating Winston loggers.
string
# static readonly exports.LogLevel
Defines the different levels of logging for the application.
An enum for log levels.
string
# static readonly exports.LoggingMode
Defines the different output formats for log messages.
An enum for logging output modes.
Methods
# static escapeRegExp(string) → {string}
This function adds backslashes before characters that have a special meaning in regular expressions, which allows 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 that is safe for use in regular expressions.
string
# static formatMs(ms) → {string}
This function breaks the duration into hours, minutes, seconds, and milliseconds, and returns a zero-padded string.
Formats milliseconds into hh:mm:ss.mmm.
Parameters:
| Name | Type | Description |
|---|---|---|
ms |
number
|
The milliseconds to format. |
The formatted duration string.
string
# static getObjectName(value) → {string}
This function returns the name of the given object, which can be a class, an instance of a class, a function, or a primitive value.
Gets the name of an object.
Parameters:
| Name | Type | Description |
|---|---|---|
value |
unknown
|
The value to get the name of. |
The name of the object.
string
# static isBrowser() → {boolean}
This function 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 isClass(value) → {boolean}
This function determines if the given value is a class constructor.
Checks if a value is a class.
Parameters:
| Name | Type | Description |
|---|---|---|
value |
unknown
|
The value to check. |
true if the value is a class, false otherwise.
boolean
# static isFunction(value) → {boolean}
This function determines if the given value is a function, but not a class.
Checks if a value is a function.
Parameters:
| Name | Type | Description |
|---|---|---|
value |
unknown
|
The value to check. |
true if the value is a function, false otherwise.
boolean
# static isInstance(value) → {boolean}
This function determines if the given value is an instance of a class.
Checks if a value is an instance of a class.
Parameters:
| Name | Type | Description |
|---|---|---|
value |
unknown
|
The value to check. |
true if the value is an instance of a class, false otherwise.
boolean
# static isMethod(value) → {boolean}
This function determines if the given value is a method.
Checks if a value is a method.
Parameters:
| Name | Type | Description |
|---|---|---|
value |
unknown
|
The value to check. |
true if the value is a method, false otherwise.
boolean
# static now() → {number}
This function chooses the most precise timer available in the current runtime, preferring performance.now or process.hrtime.bigint.
A high-resolution clock accessor that returns milliseconds.
The milliseconds that have elapsed, according to the best available clock.
number
# static padEnd(str, length, charopt) → {string}
This function 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. |
If the padding character is not exactly one character long.
Error
The padded string.
string
# static patchPlaceholders(input, values, prefixopt, suffixopt, flagsopt) → {string}
This function interpolates a string by replacing placeholders of the form ${variableName} with the corresponding values from the provided object. If a placeholder does not have a corresponding value, it is left unchanged in the string.
Replaces placeholders in a string with the provided values.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
input |
string
|
The input string containing the placeholders to be replaced. |
||
values |
Record.<string, (number|string)>
|
An object containing key-value pairs for the replacement. |
||
prefix |
string
|
<optional> |
"${" | The prefix for the placeholders. |
suffix |
string
|
<optional> |
"}" | The suffix for the placeholders. |
flags |
string
|
<optional> |
"g" | The regular expression flags to use. |
The interpolated string with the placeholders replaced by their corresponding values.
string
# static patchString(input, values, flagsopt) → {string}
This function iterates through a set of key-value pairs and replaces all occurrences of each key in the input string with its corresponding value. It 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 the replacements will be made. |
||
values |
Record.<string, (number|string)>
|
An object containing key-value pairs for the replacement. |
||
flags |
string
|
<optional> |
"g" | The regular expression flags to control the replacement behavior. |
The string with all the specified replacements applied.
string
# static sf(string, …args) → {string}
This function replaces placeholders in a string with the provided arguments.
A utility function that provides string formatting functionality that is similar to C#'s string.format.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
string |
string
|
The string to format. |
|
args |
string
|
number
|
Record.<string, any>
|
<repeatable> |
The arguments to use for formatting. |
The formatted string.
string
# static stringFormat()
This function is deprecated. Use sf instead.
A utility function that provides string formatting functionality that is similar to C#'s string.format.
- Deprecated:
- Yes
- See:
-
- sf
# static toCamelCase(text) → {string}
This function 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}
This function transforms the input string into uppercase with words separated by underscores, which is a format that is 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}
This function 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}
This function 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}
This function 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)
This type covers variadic functions where the arguments and return types are not constrained, which enables the logging layer to accept any callable.
A generic function signature for loosely typed callbacks.
Parameters:
| Name | Type | Description |
|---|---|---|
args |
Array
|
object
# Class
Describes a constructor that produces instances of type T. This allows APIs to accept class references for context-aware logging.
A constructable class type.
Properties:
| Name | Type | Description |
|---|---|---|
...args: |
T
|
any[] |
# EnvironmentFactory(args)
This describes factories that construct Environment derivatives with custom initialization.
A factory type for creating Environment instances.
Parameters:
| Name | Type | Description |
|---|---|---|
args |
Array
|
object
# Lap
This captures the lap index, an optional label, the elapsed milliseconds for the lap, and the cumulative elapsed time since the stopwatch started.
A snapshot of a recorded lap interval.
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
index |
number
|
The zero-based lap order. |
|
label |
string
|
<optional> |
An optional label that describes the lap. |
ms |
number
|
The duration of the lap in milliseconds. |
|
totalMs |
number
|
The 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(objectopt, configopt, args)
This allows consumers to override the logger construction with custom implementations.
A factory signature for creating logger instances.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
object |
string
|
<optional> |
|
config |
Partial.<LoggingConfig>
|
<optional> |
|
args |
Array
|
object
# LoggingConfig
Defines the log level, verbosity, and other settings for logging.
Configuration for the logging system.
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
env |
string
|
The environment, e.g., "development", "production". |
|
level |
LogLevel
|
The logging level. |
|
logLevel |
boolean
|
<optional> |
Whether to display the log level in the output. |
verbose |
number
|
The verbosity level. |
|
contextSeparator |
string
|
The separator to use between context entries. |
|
separator |
string
|
The separator to use between log components. |
|
style |
boolean
|
<optional> |
Whether to apply styling to the log output. |
timestamp |
boolean
|
<optional> |
Whether to include timestamps in log messages. |
timestampFormat |
string
|
<optional> |
The 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. |
format |
LoggingMode
|
The output format for log messages. |
|
pattern |
string
|
The pattern to use for formatting log messages. |
|
correlationId |
string
|
number
|
<optional> |
A correlation ID for tracking related log messages. |
filters |
Array.<string>
|
Array.<LoggingFilter>
|
<optional> |
An array of filters to apply to log messages. |
transports |
Array.<TRANSPORT>
|
<optional> |
An array of transports to use for logging. |
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> |
|
transports |
Array
|
<optional> |
string
|
Class.<any>
|
AnyFunction
# LoggingContext
Allows the logging system to resolve context names from strings, constructors, or functions.
A context descriptor that is accepted when requesting a logger instance.
object
# NumericLogLevelsShape
This provides a numeric representation of log levels for comparison and filtering.
The numeric values that are associated with log levels.
Properties:
| Name | Type | Description |
|---|---|---|
benchmark |
number
|
The numeric value for the benchmark level (0). |
error |
number
|
The numeric value for the error level (3). |
warn |
number
|
The numeric value for the warn level (6). |
info |
number
|
The numeric value for the info level (9). |
verbose |
number
|
The numeric value for the verbose level (12). |
debug |
number
|
The numeric value for the debug level (15). |
trace |
number
|
The numeric value for the trace level (18). |
silly |
number
|
The numeric value for the silly level (21). |
# ReplacementFunction(substring, args)
This function receives the matched substring and additional capture arguments, and returns the replacement text that will be injected into the log message.
A replacement callback that is used to transform RegExp matches.
Parameters:
| Name | Type | Description |
|---|---|---|
substring |
string
|
|
args |
Array
|
string
|
Object
# StringLike
Represents either a literal string or an object that has a toString() method. This allows for the lazy stringification of complex payloads.
A string-compatible value that can be accepted by the logging APIs.
Properties:
| Name | Type | Description |
|---|---|---|
toString |
function
|