Formatters API Reference
API reference for message formatting utilities in DoubleTie Logger.
Formatters API Reference
This reference documents the message formatting utilities in DoubleTie Logger.
registerFormatter(name, formatter)
Registers a custom formatter for log messages.
Signature:
Parameters:
Parameter | Type | Description |
---|---|---|
name | string | Name to identify the formatter |
formatter | Formatter | The formatter function |
Example:
getFormatter(name?)
Gets a formatter by name, falling back to default if not found.
Signature:
Parameters:
Parameter | Type | Default | Description |
---|---|---|---|
name | string | 'default' | The formatter name to retrieve |
Returns: The formatter function
Example:
formatMessage(level, message, args?, formatterName?, appName?)
Formats a log message using the specified formatter.
Signature:
Parameters:
Parameter | Type | Default | Description |
---|---|---|---|
level | LogLevel | - | Log level |
message | string | - | Log message |
args | unknown[] | [] | Additional log arguments |
formatterName | string | 'default' | Name of formatter to use |
appName | string | undefined | Application name |
Returns: Formatted log message
Example:
Formatter
Type
The type definition for formatter functions.
Signature:
Parameters:
Parameter | Type | Description |
---|---|---|
level | LogLevel | The log level ('error', 'warn', 'info', 'success', 'debug') |
message | string | The message string being logged |
args | unknown[] | Array of additional arguments passed to the log method |
appName | string | Optional application name for namespace separation |
Returns: A formatted string
Built-in Formatters
DoubleTie Logger includes the following built-in formatters:
'default'
The default formatter that includes timestamps, colored log levels, and structured data formatting.
Features:
- Color-coded log levels (in terminal environments)
- ISO timestamp
- Application name prefix (when provided)
- Pretty-printed JSON for object arguments
- Support for multiple arguments
Example Output:
Creating Specialized Formatters
Here are examples of specialized formatters for different use cases: