logging-best-practices
Implement structured logging with JSON formats, log levels (DEBUG, INFO, WARN, ERROR), contextual logging, PII handling, and centralized logging. Use for logging, observability, log levels, structured logs, or debugging.
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o logging-best-practices.zip https://jpskill.com/download/21461.zip && unzip -o logging-best-practices.zip && rm logging-best-practices.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/21461.zip -OutFile "$d\logging-best-practices.zip"; Expand-Archive "$d\logging-best-practices.zip" -DestinationPath $d -Force; ri "$d\logging-best-practices.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
logging-best-practices.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
logging-best-practicesフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 10
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
ロギングのベストプラクティス
目次
概要
アプリケーション全体で構造化され、安全で、パフォーマンスの高いロギングを実装するための包括的なガイドです。ログレベル、構造化ロギング形式、コンテキスト情報、PII保護、および集中型ロギングシステムについて説明します。
使用場面
- アプリケーションのロギングインフラストラクチャをセットアップする場合
- 構造化ロギングを実装する場合
- 異なる環境向けにログレベルを設定する場合
- ログ内の機密データを管理する場合
- 集中型ロギングをセットアップする場合
- 分散トレーシングを実装する場合
- 本番環境の問題をデバッグする場合
- ロギング規制に準拠する場合
クイックスタート
最小限の動作例です。
// logger.ts
enum LogLevel {
DEBUG = 0, // 詳細なデバッグ情報
INFO = 1, // 一般的な情報メッセージ
WARN = 2, // 警告メッセージ、潜在的に有害
ERROR = 3, // エラーメッセージ、アプリケーションは続行可能
FATAL = 4, // 致命的なエラー、アプリケーションは停止必須
}
class Logger {
constructor(private minLevel: LogLevel = LogLevel.INFO) {}
debug(message: string, context?: object) {
if (this.minLevel <= LogLevel.DEBUG) {
this.log(LogLevel.DEBUG, message, context);
}
}
info(message: string, context?: object) {
if (this.minLevel <= LogLevel.INFO) {
this.log(LogLevel.INFO, message, context);
}
}
warn(message: string, context?: object) {
// ... (完全な実装についてはリファレンスガイドを参照してください)
リファレンスガイド
references/ ディレクトリにある詳細な実装です。
| ガイド | 内容 |
|---|---|
| Log Levels | ログレベル |
| Structured Logging (JSON) | 構造化ロギング (JSON) |
| Contextual Logging | コンテキストロギング |
| PII and Sensitive Data Handling | PIIおよび機密データ処理 |
| Performance Logging | パフォーマンスロギング |
| Centralized Logging | 集中型ロギング |
| Distributed Tracing | 分散トレーシング |
| Log Sampling (High-Volume Services) | ログサンプリング (高負荷サービス) |
ベストプラクティス
✅ 実施すべきこと
- 本番環境では構造化ロギング (JSON) を使用してください
- すべてのログに相関/リクエストIDを含めてください
- 適切なレベルでログを記録してください (DEBUGを使いすぎないでください)
- 機密データ (PII、パスワード、トークン) を編集してください
- コンテキスト (userId、requestIdなど) を含めてください
- 完全なスタックトレース付きでエラーをログに記録してください
- 分散システムでは集中型ロギングを使用してください
- ディスク容量を管理するためにログローテーションを設定してください
- ログの量とコストを監視してください
- パフォーマンスのために非同期ロギングを使用してください
- ISO 8601形式のタイムスタンプを含めてください
- ビジネスイベント (ユーザーアクション、トランザクション) をログに記録してください
- エラーパターンに対するアラートを設定してください
❌ 実施すべきでないこと
- パスワード、トークン、または機密データをログに記録しないでください
- 本番環境で console.log を使用しないでください
- デフォルトで本番環境で DEBUG レベルでログを記録しないでください
- 密なループ内でログを記録しないでください (サンプリングを使用してください)
- 匿名化せずに PII を含めないでください
- ログローテーションを無視しないでください (ディスクがいっぱいになります)
- ホットパスで同期ロギングを使用しないでください
- 必要なく複数のトランスポートにログを記録しないでください
- エラースタックトレースを含めるのを忘れないでください
- バイナリデータや大きなオブジェクトをログに記録しないでください
- 文字列連結を使用しないでください (構造化フィールドを使用してください)
- 高負荷APIですべてのリクエストをログに記録しないでください
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Logging Best Practices
Table of Contents
Overview
Comprehensive guide to implementing structured, secure, and performant logging across applications. Covers log levels, structured logging formats, contextual information, PII protection, and centralized logging systems.
When to Use
- Setting up application logging infrastructure
- Implementing structured logging
- Configuring log levels for different environments
- Managing sensitive data in logs
- Setting up centralized logging
- Implementing distributed tracing
- Debugging production issues
- Compliance with logging regulations
Quick Start
Minimal working example:
// logger.ts
enum LogLevel {
DEBUG = 0, // Detailed information for debugging
INFO = 1, // General informational messages
WARN = 2, // Warning messages, potentially harmful
ERROR = 3, // Error messages, application can continue
FATAL = 4, // Critical errors, application must stop
}
class Logger {
constructor(private minLevel: LogLevel = LogLevel.INFO) {}
debug(message: string, context?: object) {
if (this.minLevel <= LogLevel.DEBUG) {
this.log(LogLevel.DEBUG, message, context);
}
}
info(message: string, context?: object) {
if (this.minLevel <= LogLevel.INFO) {
this.log(LogLevel.INFO, message, context);
}
}
warn(message: string, context?: object) {
// ... (see reference guides for full implementation)
Reference Guides
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| Log Levels | Log Levels |
| Structured Logging (JSON) | Structured Logging (JSON) |
| Contextual Logging | Contextual Logging |
| PII and Sensitive Data Handling | PII and Sensitive Data Handling |
| Performance Logging | Performance Logging |
| Centralized Logging | Centralized Logging |
| Distributed Tracing | Distributed Tracing |
| Log Sampling (High-Volume Services) | Log Sampling (High-Volume Services) |
Best Practices
✅ DO
- Use structured logging (JSON) in production
- Include correlation/request IDs in all logs
- Log at appropriate levels (don't overuse DEBUG)
- Redact sensitive data (PII, passwords, tokens)
- Include context (userId, requestId, etc.)
- Log errors with full stack traces
- Use centralized logging in distributed systems
- Set up log rotation to manage disk space
- Monitor log volume and costs
- Use async logging for performance
- Include timestamps in ISO 8601 format
- Log business events (user actions, transactions)
- Set up alerts for error patterns
❌ DON'T
- Log passwords, tokens, or sensitive data
- Use console.log in production
- Log at DEBUG level in production by default
- Log inside tight loops (use sampling)
- Include PII without anonymization
- Ignore log rotation (disk will fill up)
- Use synchronous logging in hot paths
- Log to multiple transports without need
- Forget to include error stack traces
- Log binary data or large objects
- Use string concatenation (use structured fields)
- Log every single request in high-volume APIs
同梱ファイル
※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。
- 📄 SKILL.md (3,807 bytes)
- 📎 references/centralized-logging.md (1,827 bytes)
- 📎 references/contextual-logging.md (2,741 bytes)
- 📎 references/distributed-tracing.md (1,609 bytes)
- 📎 references/log-levels.md (2,096 bytes)
- 📎 references/log-sampling-high-volume-services.md (1,173 bytes)
- 📎 references/performance-logging.md (1,388 bytes)
- 📎 references/pii-and-sensitive-data-handling.md (1,889 bytes)
- 📎 references/structured-logging-json.md (3,012 bytes)
- 📎 scripts/health-check.sh (383 bytes)