@davaux/logger
v0.9.0
Published
Request logging middleware for Davaux
Downloads
215
Readme
@davaux/logger
Request logging middleware for Davaux.
Installation
npm install @davaux/loggerSetup
// davaux.config.ts
import { defineConfig } from 'davaux/config'
import { logger } from '@davaux/logger'
export default defineConfig({
middleware: [
logger({ ignore: ['/_davaux', '/health'] }),
],
})Output formats
Defaults to 'pretty' (coloured) in development and 'json' (newline-delimited) when NODE_ENV=production.
Pretty:
GET /api/users 200 12ms 1.2KB
POST /login 302 45msJSON:
{"time":"2025-01-01T12:00:00.000Z","method":"GET","path":"/api/users","status":200,"duration":12,"contentLength":1234}Options
| Option | Type | Default | Description |
|---|---|---|---|
| format | 'pretty' \| 'json' | Auto by NODE_ENV | Output format |
| ignore | string[] | [] | Paths to skip. Exact and prefix matches supported |
| serializer | (entry: LogEntry) => void | — | Custom log handler. When set, format is ignored |
LogEntry fields
Relevant when using a custom serializer:
| Field | Type | Description |
|---|---|---|
| method | string | HTTP method (uppercased) |
| path | string | Request URL path |
| status | number | Response status code |
| duration | number | Request duration in milliseconds |
| contentLength | number \| undefined | Response body size in bytes, or undefined when Content-Length is absent |
| time | string | ISO 8601 timestamp of when the request completed |
