express-lifecycle-logger
v1.0.1
Published
Logs when each Express route starts, finishes, or errors — includes timestamps and durations
Downloads
18
Maintainers
Readme
🪶 express-lifecycle-logger
🧭 Express middleware that logs when each route starts, finishes, or errors — including timestamps and durations.
Perfect for debugging, profiling, or adding simple request tracing to your Express apps.
🚀 Features
- Logs start, finish, and error events per request
- Shows method, URL, status code, and duration
- Supports custom loggers (
winston,pino, etc.) - Generates unique request IDs
- Optional header inclusion and key redaction
- Written in TypeScript with full type definitions
📦 Installation
npm install express-lifecycle-logger
# or
pnpm add express-lifecycle-logger
# or
yarn add express-lifecycle-logger
## 🧩 Usage Example
Here’s how to use **express-lifecycle-logger** in your Express app:
```ts
import express from "express";
import { lifecycleLogger } from "express-lifecycle-logger";
const app = express();
app.use(
lifecycleLogger({
includeHeaders: true,
redactKeys: ["authorization", "cookie"],
generateRequestId: () => Math.random().toString(36).slice(2, 10),
})
);
app.get("/", (req, res) => res.send("Lifecycle logger running ✅"));
app.listen(3000, () => console.log("Listening on port 3000"));