Result Logging API Reference
API reference for Result pattern logging utilities in DoubleTie Logger.
Result Logging API Reference
This reference documents the Result pattern logging utilities in DoubleTie Logger.
logResult(result, logger?, messagePrefix?)
Logs any errors in a Result without changing the Result flow.
Signature:
Parameters:
Parameter | Type | Default | Description |
---|---|---|---|
result | Result<T, E> | - | The Result to check for errors |
logger | Pick<Logger, 'error'> | default logger | An object with an error method for logging |
messagePrefix | string | '' | Prefix for the error message |
Returns: The original Result unchanged
Example:
logResultAsync(resultAsync, logger?, messagePrefix?)
Logs any errors in a ResultAsync without changing the ResultAsync flow.
Signature:
Parameters:
Parameter | Type | Default | Description |
---|---|---|---|
resultAsync | ResultAsync<T, E> | - | The ResultAsync to check for errors |
logger | Pick<Logger, 'error'> | default logger | An object with an error method for logging |
messagePrefix | string | '' | Prefix for the error message |
Returns: The original ResultAsync unchanged
Example:
LoggableError
Interface
The interface for error objects that can be properly logged.
Signature:
Properties:
Property | Type | Required | Description |
---|---|---|---|
message | string | Yes | A human-readable error message |
code | string | No | An optional error code |
[key: string] | unknown | No | Any additional properties |
Example:
Pattern: Using with Custom Error Types
For custom error types, ensure they implement the LoggableError
interface:
Pattern: Chaining Multiple Operations
You can chain multiple operations with logging at each step: