Agent skill
structured-logging-standardizer
Enforces consistent structured logging with request correlation IDs, standardized log schema, middleware integration, and best practices. Use for "structured logging", "log standardization", "request tracing", or "log correlation".
Install this agent skill to your Project
npx add-skill https://github.com/patricio0312rev/skills/tree/main/performance/structured-logging-standardizer
SKILL.md
Structured Logging Standardizer
Implement consistent, queryable, correlated logs.
Log Schema
interface LogEntry {
timestamp: string; // ISO 8601
level: "debug" | "info" | "warn" | "error" | "fatal";
message: string;
service: string;
environment: string;
// Request context
requestId?: string;
traceId?: string;
userId?: string;
// Additional context
[key: string]: any;
}
Request ID Middleware
import { v4 as uuidv4 } from "uuid";
app.use((req, res, next) => {
// Generate or use existing request ID
req.id = req.headers["x-request-id"] || uuidv4();
// Add to response headers
res.setHeader("x-request-id", req.id);
// Store in async local storage
asyncLocalStorage.run(new Map(), () => {
asyncLocalStorage.getStore()?.set("requestId", req.id);
next();
});
});
// Logger with request context
const logger = pino({
mixin() {
return {
requestId: asyncLocalStorage.getStore()?.get("requestId"),
};
},
});
Standardized Logger
class StandardLogger {
private logger = pino();
info(message: string, context?: Record<string, any>) {
this.logger.info(
{
...this.getContext(),
...context,
},
message
);
}
error(message: string, error?: Error, context?: Record<string, any>) {
this.logger.error(
{
...this.getContext(),
...context,
error: {
message: error?.message,
stack: error?.stack,
name: error?.name,
},
},
message
);
}
private getContext() {
return {
requestId: asyncLocalStorage.getStore()?.get("requestId"),
userId: asyncLocalStorage.getStore()?.get("userId"),
};
}
}
Best Practices
// ✅ DO: Structured fields
logger.info({ userId: '123', action: 'purchase', amount: 99.99 }, 'Purchase completed');
// ❌ DON'T: String interpolation
logger.info(\`User 123 purchased for $99.99\`);
// ✅ DO: Consistent field names
logger.info({ duration_ms: 150 }, 'Request completed');
// ❌ DON'T: Inconsistent naming
logger.info({ durationMs: 150 }, 'Request done');
Output Checklist
- Request ID middleware
- Structured log schema
- Correlation IDs
- Standardized logger
- Best practices documented ENDFILE
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
rate-limiting-abuse-protection
Implements rate limiting and abuse prevention with per-route policies, IP/user-based limits, sliding windows, safe error responses, and observability. Use when adding "rate limiting", "API protection", "abuse prevention", or "DDoS protection".
rbac-permissions-builder
Implements role-based access control with permission matrix, route guards, policy functions, and UI permission hints. Provides middleware/guards, helper utilities, test suggestions, and permission checking patterns. Use when building "RBAC", "permissions", "access control", or "authorization".
websocket-realtime-builder
Implements real-time features using WebSockets with Socket.io, rooms, authentication, and reconnection handling. Use when users request "real-time updates", "WebSocket", "Socket.io", "live chat", or "push notifications".
webhook-receiver-hardener
Secures webhook receivers with signature verification, retry handling, deduplication, idempotency keys, and error responses. Provides verification code, dedupe storage strategy, runbook for incidents. Use when implementing "webhooks", "webhook security", "event receivers", or "third-party integrations".
auth-module-builder
Implements secure authentication patterns including login/registration, session management, JWT tokens, password hashing, cookie settings, and CSRF protection. Provides auth routes, middleware, security configurations, and threat model documentation. Use when building "authentication", "login system", "JWT auth", or "session management".
rest-to-graphql-migrator
Migrates REST APIs to GraphQL incrementally with schema stitching, REST datasources, and gradual endpoint migration. Use when users request "migrate to GraphQL", "REST to GraphQL", "GraphQL wrapper", or "API modernization".
Didn't find tool you were looking for?