Logging Basics
Understanding how vestig handles structured logging.
Creating a Logger
There are two ways to use vestig:
Default Logger
The quickest way to start logging:
typescript
Custom Logger
For more control, create your own instance:
typescript
Log Entry Structure
Every log entry includes:
typescript
Example Output
typescript
Produces (in structured mode):
json
Logging with Metadata
Pass any object as the second argument:
typescript
Logging Errors
Pass an Error object for automatic serialization:
typescript
This produces:
json
Combining Error with Metadata
typescript
Logger Configuration
typescript
Environment-Based Configuration
Vestig reads these environment variables:
| Variable | Type | Default | Description |
|---|---|---|---|
VESTIG_LEVEL | string | 'info' | Minimum log level |
VESTIG_ENABLED | boolean | true | Enable/disable logging |
VESTIG_STRUCTURED | boolean | auto | Force JSON output |
VESTIG_SANITIZE | boolean | true | Enable PII sanitization |
VESTIG_SANITIZE_PRESET | string | 'default' | Sanitization preset |
NODE_ENV | string | — | Auto-enables structured in production |
Next Steps
- Log Levels — Understanding log level hierarchy
- Structured Output — JSON formatting options
- Child Loggers — Namespaced logging