API Reference
Complete API documentation for Vestig.
createLogger
Creates a new logger instance with custom configuration.
typescript
LoggerConfig
| Option | Type | Default | Description |
|---|---|---|---|
level | LogLevel | 'info' | Minimum log level |
enabled | boolean | true | Enable/disable logging |
structured | boolean | false (dev) / true (prod) | JSON output |
sanitize | boolean | true | Enable PII sanitization |
sanitizeFields | string[] | [] | Additional fields to redact |
context | Record<string, unknown> | {} | Static context |
namespace | string | '' | Logger namespace |
Example
typescript
Default Logger
A pre-configured logger instance for quick usage.
typescript
Methods
| Method | Description |
|---|---|
trace(message, ...args) | Log at trace level |
debug(message, ...args) | Log at debug level |
info(message, ...args) | Log at info level |
warn(message, ...args) | Log at warn level |
error(message, ...args) | Log at error level |
setLevel(level) | Change minimum level |
getLevel() | Get current level |
enable() | Enable logging |
disable() | Disable logging |
isEnabled() | Check if enabled |
child(namespace, config?) | Create child logger |
flush() | Flush pending logs |
Context Functions
withContext
Runs a function with logging context.
typescript
withContextAsync
Async version of withContext.
typescript
getContext
Gets the current context.
typescript
createCorrelationContext
Creates a new correlation context with IDs.
typescript
ID Generators
generateRequestId
Generates a UUID v4 request ID.
typescript
generateTraceId
Generates a 32-character hex trace ID (W3C Trace Context).
typescript
generateSpanId
Generates a 16-character hex span ID.
typescript
Sanitization
sanitize
Sanitizes an object, redacting sensitive fields.
typescript
createSanitizer
Creates a sanitizer with custom fields.
typescript
Utilities
serializeError
Converts an Error to a serializable object.
typescript
isError
Type guard for Error objects.
typescript
getErrorMessage
Extracts error message from unknown value.
typescript
Constants
LOG_LEVELS
Map of log levels to numeric values.
typescript
RUNTIME
Current runtime identifier.
typescript
CAPABILITIES
Runtime capability flags.
typescript
ENV_VARS
Environment variable names.
typescript
Types
typescript