vestig 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +319 -0
- package/package.json +4 -4
package/README.md
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# 👣 Vestig
|
|
4
|
+
|
|
5
|
+
**Leave a trace.**
|
|
6
|
+
|
|
7
|
+
A modern, runtime-agnostic structured logging library with automatic PII sanitization and context propagation.
|
|
8
|
+
|
|
9
|
+
[](https://github.com/Arakiss/vestig/actions/workflows/ci.yml)
|
|
10
|
+
[](https://www.npmjs.com/package/vestig)
|
|
11
|
+
[](https://opensource.org/licenses/MIT)
|
|
12
|
+
[](https://www.typescriptlang.org/)
|
|
13
|
+
[](https://github.com/Arakiss/vestig/blob/main/CONTRIBUTING.md)
|
|
14
|
+
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Why Vestig?
|
|
20
|
+
|
|
21
|
+
*Vestig* — from Latin *vestigium* (trace, footprint). Leave a trace of what happened.
|
|
22
|
+
|
|
23
|
+
| Feature | Vestig | Pino | Winston |
|
|
24
|
+
|---------|:-----:|:----:|:-------:|
|
|
25
|
+
| Runtime Agnostic | ✅ | ❌ | ❌ |
|
|
26
|
+
| Auto PII Sanitization | ✅ | ❌ | ❌ |
|
|
27
|
+
| GDPR/HIPAA/PCI-DSS Presets | ✅ | ❌ | ❌ |
|
|
28
|
+
| Zero Config | ✅ | ✅ | ❌ |
|
|
29
|
+
| TypeScript First | ✅ | ✅ | ⚠️ |
|
|
30
|
+
| Edge Runtime Support | ✅ | ❌ | ❌ |
|
|
31
|
+
| Browser Support | ✅ | ❌ | ⚠️ |
|
|
32
|
+
| Context Propagation | ✅ | ❌ | ❌ |
|
|
33
|
+
| Multiple Transports | ✅ | ✅ | ✅ |
|
|
34
|
+
| Zero Dependencies | ✅ | ❌ | ❌ |
|
|
35
|
+
|
|
36
|
+
**Vestig is the only logging library that:**
|
|
37
|
+
- Works everywhere (Node.js, Bun, Deno, Edge, Browser)
|
|
38
|
+
- Automatically sanitizes PII with compliance presets
|
|
39
|
+
- Propagates context through async operations
|
|
40
|
+
- Has zero runtime dependencies
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# bun
|
|
46
|
+
bun add vestig
|
|
47
|
+
|
|
48
|
+
# npm
|
|
49
|
+
npm install vestig
|
|
50
|
+
|
|
51
|
+
# pnpm
|
|
52
|
+
pnpm add vestig
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Quick Start
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { log } from 'vestig'
|
|
59
|
+
|
|
60
|
+
// Simple logging
|
|
61
|
+
log.info('Hello world')
|
|
62
|
+
log.error('Something failed', { userId: 123 })
|
|
63
|
+
|
|
64
|
+
// Sensitive data is automatically redacted
|
|
65
|
+
log.info('User login', {
|
|
66
|
+
email: 'user@example.com', // → us***@example.com
|
|
67
|
+
password: 'secret123', // → [REDACTED]
|
|
68
|
+
creditCard: '4111111111111111', // → ****1111
|
|
69
|
+
})
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Features
|
|
73
|
+
|
|
74
|
+
### Multi-Transport Support
|
|
75
|
+
|
|
76
|
+
Send logs to multiple destinations simultaneously:
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { createLogger, ConsoleTransport, HTTPTransport, DatadogTransport } from 'vestig'
|
|
80
|
+
|
|
81
|
+
const log = createLogger()
|
|
82
|
+
|
|
83
|
+
// Add HTTP transport for centralized logging
|
|
84
|
+
log.addTransport(new HTTPTransport({
|
|
85
|
+
name: 'api-logs',
|
|
86
|
+
url: 'https://logs.example.com/ingest',
|
|
87
|
+
headers: { 'Authorization': 'Bearer token' },
|
|
88
|
+
}))
|
|
89
|
+
|
|
90
|
+
// Add Datadog for observability
|
|
91
|
+
log.addTransport(new DatadogTransport({
|
|
92
|
+
name: 'datadog',
|
|
93
|
+
apiKey: process.env.DD_API_KEY,
|
|
94
|
+
service: 'my-app',
|
|
95
|
+
tags: ['env:production'],
|
|
96
|
+
}))
|
|
97
|
+
|
|
98
|
+
// Initialize transports (starts flush timers)
|
|
99
|
+
await log.init()
|
|
100
|
+
|
|
101
|
+
// All logs go to console, HTTP endpoint, and Datadog
|
|
102
|
+
log.info('Server started', { port: 3000 })
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Available Transports
|
|
106
|
+
|
|
107
|
+
| Transport | Description | Use Case |
|
|
108
|
+
|-----------|-------------|----------|
|
|
109
|
+
| `ConsoleTransport` | Console output with colors | Development, debugging |
|
|
110
|
+
| `HTTPTransport` | Send to any HTTP endpoint | Custom log aggregation |
|
|
111
|
+
| `FileTransport` | Write to files with rotation | Server-side logging |
|
|
112
|
+
| `DatadogTransport` | Datadog Log Management | Production observability |
|
|
113
|
+
|
|
114
|
+
### PII Sanitization with Presets
|
|
115
|
+
|
|
116
|
+
Choose from compliance-focused presets:
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import { Sanitizer } from 'vestig'
|
|
120
|
+
|
|
121
|
+
// GDPR compliance (EU data protection)
|
|
122
|
+
const gdprSanitizer = Sanitizer.fromPreset('gdpr')
|
|
123
|
+
|
|
124
|
+
// HIPAA compliance (healthcare)
|
|
125
|
+
const hipaaSanitizer = Sanitizer.fromPreset('hipaa')
|
|
126
|
+
|
|
127
|
+
// PCI-DSS compliance (payment cards)
|
|
128
|
+
const pciSanitizer = Sanitizer.fromPreset('pci-dss')
|
|
129
|
+
|
|
130
|
+
// Apply to logger
|
|
131
|
+
const log = createLogger({
|
|
132
|
+
sanitize: 'gdpr', // Use preset name directly
|
|
133
|
+
})
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
| Preset | Fields Protected | Patterns Applied |
|
|
137
|
+
|--------|-----------------|------------------|
|
|
138
|
+
| `none` | None | None |
|
|
139
|
+
| `minimal` | password, secret, token, key | None |
|
|
140
|
+
| `default` | 26 common fields | Email, Credit Card, JWT |
|
|
141
|
+
| `gdpr` | + name, address, phone, IP | + IP addresses, phone |
|
|
142
|
+
| `hipaa` | + patient, medical, SSN | + SSN pattern |
|
|
143
|
+
| `pci-dss` | + card, CVV, PIN | Full card detection |
|
|
144
|
+
|
|
145
|
+
### Custom Sanitization
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
import { Sanitizer } from 'vestig'
|
|
149
|
+
|
|
150
|
+
const sanitizer = new Sanitizer({
|
|
151
|
+
fields: [
|
|
152
|
+
'customSecret',
|
|
153
|
+
{ type: 'prefix', value: 'private_' },
|
|
154
|
+
{ type: 'contains', value: 'token' },
|
|
155
|
+
],
|
|
156
|
+
patterns: [{
|
|
157
|
+
name: 'internal-id',
|
|
158
|
+
pattern: /ID-[A-Z0-9]+/g,
|
|
159
|
+
replacement: '[ID_REDACTED]',
|
|
160
|
+
}],
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
const safe = sanitizer.sanitize({
|
|
164
|
+
private_key: 'abc123', // → [REDACTED]
|
|
165
|
+
auth_token: 'xyz789', // → [REDACTED]
|
|
166
|
+
internalId: 'ID-ABC123', // → [ID_REDACTED]
|
|
167
|
+
})
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Child Loggers
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
const log = createLogger({ namespace: 'app' })
|
|
174
|
+
const dbLog = log.child('database')
|
|
175
|
+
const cacheLog = log.child('cache')
|
|
176
|
+
|
|
177
|
+
dbLog.info('Query executed') // [app:database] Query executed
|
|
178
|
+
cacheLog.info('Cache hit') // [app:cache] Cache hit
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Context & Correlation IDs
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
import { withContext, createCorrelationContext } from 'vestig'
|
|
185
|
+
|
|
186
|
+
// Next.js API Route
|
|
187
|
+
export async function GET(req: Request) {
|
|
188
|
+
const context = createCorrelationContext({
|
|
189
|
+
requestId: req.headers.get('x-request-id') ?? undefined
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
return withContext(context, async () => {
|
|
193
|
+
log.info('Request started')
|
|
194
|
+
// All logs include: requestId, traceId, spanId
|
|
195
|
+
|
|
196
|
+
const result = await fetchData()
|
|
197
|
+
log.info('Request completed')
|
|
198
|
+
|
|
199
|
+
return Response.json(result)
|
|
200
|
+
})
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Configuration
|
|
205
|
+
|
|
206
|
+
### Environment Variables
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
VESTIG_LEVEL=debug # trace | debug | info | warn | error
|
|
210
|
+
VESTIG_ENABLED=true # Enable/disable logging
|
|
211
|
+
VESTIG_STRUCTURED=true # JSON output (auto-enabled in production)
|
|
212
|
+
VESTIG_SANITIZE=true # PII sanitization (default: true)
|
|
213
|
+
|
|
214
|
+
# Add to context
|
|
215
|
+
VESTIG_CONTEXT_SERVICE=api
|
|
216
|
+
VESTIG_CONTEXT_VERSION=1.0.0
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Programmatic
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
const log = createLogger({
|
|
223
|
+
level: 'debug',
|
|
224
|
+
enabled: true,
|
|
225
|
+
structured: false,
|
|
226
|
+
sanitize: 'gdpr', // or true, false, or SanitizeConfig
|
|
227
|
+
context: { environment: 'development' }
|
|
228
|
+
})
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Log Levels
|
|
232
|
+
|
|
233
|
+
| Level | Description |
|
|
234
|
+
|-------|-------------|
|
|
235
|
+
| `trace` | Very detailed debugging information |
|
|
236
|
+
| `debug` | Development debugging |
|
|
237
|
+
| `info` | General information |
|
|
238
|
+
| `warn` | Warning messages |
|
|
239
|
+
| `error` | Error messages (includes stack traces) |
|
|
240
|
+
|
|
241
|
+
## Runtime Detection
|
|
242
|
+
|
|
243
|
+
Vestig automatically detects and adapts to:
|
|
244
|
+
|
|
245
|
+
- **Node.js** - Full features with AsyncLocalStorage
|
|
246
|
+
- **Bun** - Full features with AsyncLocalStorage
|
|
247
|
+
- **Deno** - Full features with AsyncLocalStorage
|
|
248
|
+
- **Edge Runtime** - Vercel Edge, Cloudflare Workers
|
|
249
|
+
- **Browser** - Client-side logging with sanitization
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
import { RUNTIME, IS_SERVER, IS_EDGE } from 'vestig'
|
|
253
|
+
|
|
254
|
+
console.log(RUNTIME) // 'node' | 'bun' | 'deno' | 'edge' | 'browser'
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## Auto-Production Mode
|
|
258
|
+
|
|
259
|
+
In production (`NODE_ENV=production`), Vestig automatically:
|
|
260
|
+
|
|
261
|
+
- Sets log level to `warn`
|
|
262
|
+
- Enables structured (JSON) output
|
|
263
|
+
- Keeps sanitization enabled
|
|
264
|
+
|
|
265
|
+
## API Reference
|
|
266
|
+
|
|
267
|
+
### `createLogger(config?)`
|
|
268
|
+
|
|
269
|
+
Create a new logger instance.
|
|
270
|
+
|
|
271
|
+
### `log.trace/debug/info/warn/error(message, metadata?)`
|
|
272
|
+
|
|
273
|
+
Log at the specified level.
|
|
274
|
+
|
|
275
|
+
### `log.child(namespace, config?)`
|
|
276
|
+
|
|
277
|
+
Create a namespaced child logger.
|
|
278
|
+
|
|
279
|
+
### `log.addTransport(transport)`
|
|
280
|
+
|
|
281
|
+
Add a transport to the logger.
|
|
282
|
+
|
|
283
|
+
### `log.removeTransport(name)`
|
|
284
|
+
|
|
285
|
+
Remove a transport by name.
|
|
286
|
+
|
|
287
|
+
### `log.flush()`
|
|
288
|
+
|
|
289
|
+
Flush all buffered logs.
|
|
290
|
+
|
|
291
|
+
### `log.destroy()`
|
|
292
|
+
|
|
293
|
+
Cleanup all transports (call on shutdown).
|
|
294
|
+
|
|
295
|
+
### `withContext(context, fn)`
|
|
296
|
+
|
|
297
|
+
Run a function with the given context.
|
|
298
|
+
|
|
299
|
+
### `createCorrelationContext(existing?)`
|
|
300
|
+
|
|
301
|
+
Generate correlation IDs (requestId, traceId, spanId).
|
|
302
|
+
|
|
303
|
+
### `Sanitizer.fromPreset(preset)`
|
|
304
|
+
|
|
305
|
+
Create a sanitizer from a preset name.
|
|
306
|
+
|
|
307
|
+
## Contributing
|
|
308
|
+
|
|
309
|
+
We love contributions! Please read our [Contributing Guide](https://github.com/Arakiss/vestig/blob/main/CONTRIBUTING.md) to get started.
|
|
310
|
+
|
|
311
|
+
- 🐛 [Report bugs](https://github.com/Arakiss/vestig/issues/new?template=bug_report.md)
|
|
312
|
+
- 💡 [Request features](https://github.com/Arakiss/vestig/issues/new?template=feature_request.md)
|
|
313
|
+
- 📖 [Improve documentation](https://github.com/Arakiss/vestig/pulls)
|
|
314
|
+
|
|
315
|
+
## License
|
|
316
|
+
|
|
317
|
+
MIT © [Arakiss](https://github.com/Arakiss)
|
|
318
|
+
|
|
319
|
+
See [LICENSE](https://github.com/Arakiss/vestig/blob/main/LICENSE) for more details.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vestig",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Leave a trace. A modern, runtime-agnostic structured logging library with automatic PII sanitization and context propagation.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -56,13 +56,13 @@
|
|
|
56
56
|
"license": "MIT",
|
|
57
57
|
"repository": {
|
|
58
58
|
"type": "git",
|
|
59
|
-
"url": "git+https://github.com/Arakiss/
|
|
59
|
+
"url": "git+https://github.com/Arakiss/vestig.git",
|
|
60
60
|
"directory": "packages/vestig"
|
|
61
61
|
},
|
|
62
62
|
"bugs": {
|
|
63
|
-
"url": "https://github.com/Arakiss/
|
|
63
|
+
"url": "https://github.com/Arakiss/vestig/issues"
|
|
64
64
|
},
|
|
65
|
-
"homepage": "https://github.com/Arakiss/
|
|
65
|
+
"homepage": "https://github.com/Arakiss/vestig#readme",
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"typescript": "catalog:",
|
|
68
68
|
"@types/node": "catalog:"
|