Builds observability-focused middleware for Node APIs: structured JSON logging with pino, request IDs, latency capture, and pretty console output in development.
Agentic Workflow: Read -> Reason -> Act (api-middleware-pino-logging)
You are Api Middleware Pino Logging (backend) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — backend context for api-middleware-pino-logging
- Domain: Builds observability-focused middleware for Node APIs: structured JSON logging with pino, request IDs, latency capture, and pretty console output in development.
- pino-logging: Add structured logging middleware with correlation IDs and latency measurement —
npm install pino pino-http pino-pretty
- log-querying: Query and filter structured logs in production and development —
npm install -g pino-pretty
- Check
knowledge and prerequisites: node.js, python, express, fastify
2. Reason — think for api-middleware-pino-logging
- For
pino-logging: Add structured logging middleware with correlation IDs and latency measurement — decide which checks to run
- For
log-querying: Query and filter structured logs in production and development — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with api-middleware-pino-logging tools
- Tools:
Glob, Grep, Read, Bash, Cat (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
api-middleware-pino-logging:aadc1018
API Middleware v2 - Observability
Logging and correlation middleware for Node.js APIs.
What This Skill Does
- Adds pino-http middleware for JSON request logging
- Propagates X-Request-Id correlation IDs through the pipeline
- Measures per-request latency and status mapping
When to Use
- Debugging distributed request traces
- Switching from text logs to structured JSON
- Adding service metadata to all log lines
Real Commands
npm install pino pino-http pino-pretty
node app.js | npx pino-pretty
curl -s -H "X-Request-Id: 123e4567" http://localhost:3000/api/health
Middleware Setup
const pinoHttp = require('pino-http');
app.use(pinoHttp({
genReqId: (req) => req.headers['x-request-id'],
base: { service: 'billing-api' },
customLogLevel: (req, res, err) => err ? 'error' : res.statusCode >= 400 ? 'warn' : 'info'
}));
Testing
- Send a request with an X-Request-Id header and confirm it appears in log output
- Verify 5xx responses produce error-level log lines
- Confirm logs parse with jq for field extraction
Best Practices
- Never log bodies of auth endpoints
- Use genReqId to honor incoming correlation headers
- Keep pino as a direct dependency so serializers are stable
Capabilities
pino-logging
Add structured logging middleware with correlation IDs and latency measurement
Parameters:
base (object): Static fields merged into every log line (service name, env)
genReqId (function): Generate or extract the request correlation ID
customLogLevel (function): Map status codes to log levels
Commands:
npm install pino pino-http pino-pretty
node app.js | npx pino-pretty
curl -s -H "X-Request-Id: 123e4567" http://localhost:3000/api/health
curl -s -o /dev/null -w "%{http_code} %{time_total}s\n" http://localhost:3000/api
Examples:
- node app.js | npx pino-pretty renders human-readable logs in dev
- app.use(pinoHttp({ genReqId: (req) => req.headers['x-request-id'] }))
- curl -H 'X-Request-Id: abc' localhost:3000/ traces a single request across logs
log-querying
Query and filter structured logs in production and development
Commands:
npm install -g pino-pretty
cat app.log | pino-pretty --translateTime
jq 'select(.level >= 40)' app.log
node -r pino-pretty app.js
Examples:
References
1---2name: "api-middleware-pino-logging"3description: "Builds observability-focused middleware for Node APIs: structured JSON logging with pino, request IDs, latency capture, and pretty console output in development. Use when working with pino logging, log querying or when the user mentions pino logging, log querying."4license: "MIT"5compatibility: "Requires node.js, python, express, fastify, koa. Needs network access."6metadata:7 source: https://skillmd.com/skills/opknock/api-middleware-pino-logging8 author: Kdesk9 version: 2.0.010 category: backend11allowed-tools: "Glob Grep Read Bash(cat:*) Bash(curl:*) Bash(jq:*) Bash(node:*) Bash(npm:*)"12---1314Builds observability-focused middleware for Node APIs: structured JSON logging with pino, request IDs, latency capture, and pretty console output in development.1516## Agentic Workflow: Read -> Reason -> Act (api-middleware-pino-logging)1718You are **Api Middleware Pino Logging** (backend) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — backend context for `api-middleware-pino-logging`21- Domain: Builds observability-focused middleware for Node APIs: structured JSON logging with pino, request IDs, latency capture, and pretty console output in development.22- **pino-logging**: Add structured logging middleware with correlation IDs and latency measurement — `npm install pino pino-http pino-pretty`23- **log-querying**: Query and filter structured logs in production and development — `npm install -g pino-pretty`24- Check `knowledge` and `prerequisites: node.js, python, express, fastify`2526### 2. Reason — think for `api-middleware-pino-logging`27- For `pino-logging`: Add structured logging middleware with correlation IDs and latency measurement — decide which checks to run28- For `log-querying`: Query and filter structured logs in production and development — decide which checks to run29- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs3031### 3. Act — execute with `api-middleware-pino-logging` tools32- Tools: `Glob`, `Grep`, `Read`, `Bash`, `Cat` (see frontmatter `tools`/`allowed-tools`)33- Use `safe_path` for any write; record evidence (paths, checksums)34- Fingerprint: `api-middleware-pino-logging:aadc1018`3536# API Middleware v2 - Observability3738Logging and correlation middleware for Node.js APIs.3940## What This Skill Does41- Adds pino-http middleware for JSON request logging42- Propagates X-Request-Id correlation IDs through the pipeline43- Measures per-request latency and status mapping4445## When to Use46- Debugging distributed request traces47- Switching from text logs to structured JSON48- Adding service metadata to all log lines4950## Real Commands5152```bash53npm install pino pino-http pino-pretty54node app.js | npx pino-pretty55curl -s -H "X-Request-Id: 123e4567" http://localhost:3000/api/health56```5758## Middleware Setup5960```js61const pinoHttp = require('pino-http');62app.use(pinoHttp({63 genReqId: (req) => req.headers['x-request-id'],64 base: { service: 'billing-api' },65 customLogLevel: (req, res, err) => err ? 'error' : res.statusCode >= 400 ? 'warn' : 'info'66}));67```6869## Testing70- Send a request with an X-Request-Id header and confirm it appears in log output71- Verify 5xx responses produce error-level log lines72- Confirm logs parse with jq for field extraction7374## Best Practices75- Never log bodies of auth endpoints76- Use genReqId to honor incoming correlation headers77- Keep pino as a direct dependency so serializers are stable7879## Capabilities8081### pino-logging82Add structured logging middleware with correlation IDs and latency measurement8384**Parameters:**85- `base` (object): Static fields merged into every log line (service name, env)86- `genReqId` (function): Generate or extract the request correlation ID87- `customLogLevel` (function): Map status codes to log levels8889**Commands:**90- `npm install pino pino-http pino-pretty`91- `node app.js | npx pino-pretty`92- `curl -s -H "X-Request-Id: 123e4567" http://localhost:3000/api/health`93- `curl -s -o /dev/null -w "%{http_code} %{time_total}s\n" http://localhost:3000/api`9495**Examples:**96- node app.js | npx pino-pretty renders human-readable logs in dev97- app.use(pinoHttp({ genReqId: (req) => req.headers['x-request-id'] }))98- curl -H 'X-Request-Id: abc' localhost:3000/ traces a single request across logs99100### log-querying101Query and filter structured logs in production and development102103**Commands:**104- `npm install -g pino-pretty`105- `cat app.log | pino-pretty --translateTime`106- `jq 'select(.level >= 40)' app.log`107- `node -r pino-pretty app.js`108109**Examples:**110- -cli --help111- -api --help112113## References114- [pino-http Docs](https://github.com/pinojs/pino-http)115- [pino Docs](https://getpino.io/#/docs/)