使い方
- インストールコマンドをコピーし、自分の環境へ導入する前にソースを確認します。
- 必要なツール、認証情報、対応環境を原文で確認します。
- 入力と成果物を指定し、出力を資料と照合します。
npx skills add https://github.com/j4flmao/agent_skills_nodejs_nestjs --skill logging-and-observability開始前の確認
- 導入にはモデル契約、API枠、ファイルへのアクセス許可は含まれません。
- スター数や導入数は活動の指標であり、独立した品質・安全性試験ではありません。
見出し、例、コード、表、リンク、参照画像を含む原文を表示しています。
Logging and Observability
When to use
- Wiring observability for a new service
- Debugging cross-service requests
- Removing
console.logfrom production code
Core rules
- Structured JSON logs in production, pretty in development
- Every log entry has
timestamp,level,message,traceId - No
console.login production code - Correlation/trace ID passed through async context
- Health endpoint (
/health) and readiness endpoint (/ready)
Reference shape (TypeScript)
Logger Interface (Port)
export 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;
}JSON Logger Implementation
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));
}
}Examples — Do
this.logger.info('User created', { userId: user.id, email: user.email.value });Examples — Don't
// ❌ Console.log in production code
console.log('User created:', user);
// ❌ No trace ID
logger.info('Request processed');Checklist
- [ ] Structured JSON logger implemented
- [ ] Trace/correlation ID in every log entry
- [ ] Health and readiness endpoints created
- [ ] No
console.login production code
See reference/logging-patterns.md for full patterns.




