Loading...
Loading...
Adds structured JSON logging, correlation/trace IDs, metrics, and health endpoints. Use when wiring observability for a new service, debugging cross-service requests, or removing console.log.
npx skill4agent add j4flmao/agent_skills_nodejs_nestjs logging-and-observabilityconsole.logtimestamplevelmessagetraceIdconsole.log/health/readyexport interface Logger {
info(message: string, meta?: Record<string, unknown>): void;
warn(message: string, meta?: Record<string, unknown>): void;
error(message: string, meta?: Record<string, unknown>): void;
debug(message: string, meta?: Record<string, unknown>): void;
}export class JsonLogger implements Logger {
constructor(private traceId?: string) {}
info(message: string, meta?: Record<string, unknown>): void {
this.log('info', message, meta);
}
private log(level: string, message: string, meta?: Record<string, unknown>): void {
const entry = {
timestamp: new Date().toISOString(),
level,
message,
traceId: this.traceId,
...meta,
};
console.log(JSON.stringify(entry));
}
}this.logger.info('User created', { userId: user.id, email: user.email.value });// ❌ Console.log in production code
console.log('User created:', user);
// ❌ No trace ID
logger.info('Request processed');console.log