Skip to content
Back to skills

Collection

ASecurity

Node.jsアプリケーションのログローテーション戦略を専門とするスキル。 PM2、logrotate、Winston等を活用した効率的なログ管理を設計します。 📚 リソース参照: このスキルには以下のリソースが含まれています。 必要に応じて該当するリソースを参照してください: - `.claude/skills/log-rotation-strategies/resources/log-aggregation.md`: 集中ログ管理オプション(ELK/Datadog/CloudWatch/Loki)、サービス選定基準 - `.claude/skills/log-rotation-strategies/resources/pm2-logrotate-guide.md`: pm2-logrotate設定、max_size/retain/compress、ecosystem.config.js統合 - `.claude/skills/log-rotation-strategies/resources/rotation-patterns.md`: サイズベース・時間ベース・ハイブ...

  • 24 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 8, 2026
developmentjavascripttypescriptgojavabashnodeaws

Security analysis

A100/100

Pro scans all 21 files and shows the line behind each finding

Scanned September 8, 2026

npx -y skills add mattnigh/skills_collection --skill collection --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Collection?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Collection
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mattnigh-collection-249ade31/badge)](https://www.skillsdirectory.com/skills/mattnigh-collection-249ade31)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: .claude/skills/log-rotation-strategies/SKILL.md
description: |
  Node.jsアプリケーションのログローテーション戦略を専門とするスキル。
  PM2、logrotate、Winston等を活用した効率的なログ管理を設計します。

  📚 リソース参照:
  このスキルには以下のリソースが含まれています。
  必要に応じて該当するリソースを参照してください:

  - `.claude/skills/log-rotation-strategies/resources/log-aggregation.md`: 集中ログ管理オプション(ELK/Datadog/CloudWatch/Loki)、サービス選定基準
  - `.claude/skills/log-rotation-strategies/resources/pm2-logrotate-guide.md`: pm2-logrotate設定、max_size/retain/compress、ecosystem.config.js統合
  - `.claude/skills/log-rotation-strategies/resources/rotation-patterns.md`: サイズベース・時間ベース・ハイブリッド方式の選択基準と実装パターン
  - `.claude/skills/log-rotation-strategies/scripts/analyze-log-usage.mjs`: ログ使用量分析(ディレクトリサイズ、世代数、圧縮率)
  - `.claude/skills/log-rotation-strategies/templates/winston-rotation.template.ts`: Winston DailyRotateFile設定テンプレート(TypeScript)

  専門分野:
  - PM2ログ管理: pm2-logrotate、ログファイル設定、自動ローテーション
  - ログフォーマット: 構造化ログ、JSON形式、タイムスタンプ
  - ローテーション戦略: サイズベース、時間ベース、ハイブリッド
  - ログ集約: 集中ログ管理、外部サービス連携

  使用タイミング:
  - ログローテーションを設定する時
  - ディスク容量管理を最適化する時
  - ログフォーマットを標準化する時
  - PM2ログ設定を行う時

  Use proactively when configuring log rotation, optimizing disk usage,
version: 1.0.0
---

# Log Rotation Strategies

## 概要

ログローテーションは、ディスク容量を管理しながらログを適切に保持するための
重要な運用プラクティスです。アプリケーションの可観測性を維持しつつ、
リソース効率を最適化します。

**主要な価値**:

- ディスク容量の効率的管理
- ログの長期保持と検索性
- アプリケーションパフォーマンスの維持
- コンプライアンス要件への対応

## リソース構造

```
log-rotation-strategies/
├── SKILL.md
├── resources/
│   ├── rotation-patterns.md
│   ├── pm2-logrotate-guide.md
│   └── log-aggregation.md
├── scripts/
│   └── analyze-log-usage.mjs
└── templates/
    └── winston-rotation.template.ts
```

## コマンドリファレンス

### リソース読み取り

```bash
# ローテーションパターンガイド
cat .claude/skills/log-rotation-strategies/resources/rotation-patterns.md

# PM2ログローテーションガイド
cat .claude/skills/log-rotation-strategies/resources/pm2-logrotate-guide.md

# ログ集約ガイド
cat .claude/skills/log-rotation-strategies/resources/log-aggregation.md
```

### スクリプト実行

```bash
# ログ使用量分析
node .claude/skills/log-rotation-strategies/scripts/analyze-log-usage.mjs [log-dir]
```

### テンプレート参照

```bash
# Winstonログローテーションテンプレート
cat .claude/skills/log-rotation-strategies/templates/winston-rotation.template.ts
```

## ワークフロー

### Phase 1: ログ戦略設計

**ローテーション方式の選択**:
| 方式 | 特徴 | 適用シナリオ |
|------|------|-------------|
| サイズベース | ファイルサイズで分割 | 均一なログ量 |
| 時間ベース | 時間間隔で分割 | 時系列分析重視 |
| ハイブリッド | サイズ+時間 | 大規模本番環境 |

**判断基準**:

- [ ] 1 日あたりの予想ログ量は?
- [ ] 必要な保持期間は?
- [ ] ディスク容量の制約は?

**リソース**: `resources/rotation-patterns.md`

### Phase 2: PM2 ログ設定

**pm2-logrotate 設定**:

```bash
# インストール
pm2 install pm2-logrotate

# 設定確認
pm2 conf pm2-logrotate
```

**主要設定項目**:

```bash
pm2 set pm2-logrotate:max_size 10M      # ファイルサイズ上限
pm2 set pm2-logrotate:retain 7          # 保持世代数
pm2 set pm2-logrotate:compress true     # 圧縮有効化
pm2 set pm2-logrotate:rotateInterval '0 0 * * *'  # 毎日0時
```

**ecosystem.config.js 設定**:

```javascript
{
  error_file: './logs/error.log',
  out_file: './logs/out.log',
  log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
  merge_logs: true,
  log_type: 'json'
}
```

**リソース**: `resources/pm2-logrotate-guide.md`

### Phase 3: アプリケーションログ

**Winston ローテーション**:

```javascript
const winston = require("winston");
require("winston-daily-rotate-file");

const transport = new winston.transports.DailyRotateFile({
  filename: "logs/app-%DATE%.log",
  datePattern: "YYYY-MM-DD",
  maxSize: "20m",
  maxFiles: "14d",
  compress: true,
});
```

**Pino ローテーション**:

```javascript
const pino = require("pino");
const rfs = require("rotating-file-stream");

const stream = rfs.createStream("app.log", {
  size: "10M",
  interval: "1d",
  compress: "gzip",
  path: "./logs",
});

const logger = pino(stream);
```

### Phase 4: システムレベルローテーション

**logrotate 設定** (`/etc/logrotate.d/myapp`):

```
/var/log/myapp/*.log {
    daily
    rotate 7
    compress
    delaycompress
    missingok
    notifempty
    copytruncate
    dateext
}
```

**オプション解説**:
| オプション | 説明 |
|-----------|------|
| daily | 毎日ローテーション |
| rotate 7 | 7 世代保持 |
| compress | gzip 圧縮 |
| delaycompress | 1 世代後に圧縮 |
| copytruncate | ログを切り詰め(再起動不要) |

### Phase 5: ログ集約

**集中ログ管理オプション**:
| サービス | 特徴 |
|---------|------|
| ELK Stack | オンプレミス、高度な分析 |
| Datadog | SaaS、APM 統合 |
| CloudWatch | AWS 統合、低コスト |
| Loki | Grafana 統合、軽量 |

**リソース**: `resources/log-aggregation.md`

## ベストプラクティス

### すべきこと

1. **構造化ログ**: JSON 形式でログを出力し、解析を容易に
2. **ログレベル活用**: debug/info/warn/error を適切に使い分け
3. **タイムスタンプ統一**: ISO8601 形式でタイムゾーン明示
4. **圧縮有効化**: 古いログは gzip 圧縮でディスク節約

### 避けるべきこと

1. **無制限ログ**: サイズ・世代制限なしのログ設定
2. **console.log 依存**: 本番環境での生 console.log 使用
3. **機密情報ログ**: パスワード、トークン等のログ出力
4. **同期ログ**: 高負荷時のブロッキング I/O

## 変更履歴

| バージョン | 日付       | 変更内容 |
| ---------- | ---------- | -------- |
| 1.0.0      | 2025-11-26 | 初版作成 |

## 関連スキル

- **.claude/skills/pm2-ecosystem-config/SKILL.md** (`.claude/skills/pm2-ecosystem-config/SKILL.md`)
- **.claude/skills/process-lifecycle-management/SKILL.md** (`.claude/skills/process-lifecycle-management/SKILL.md`)
- **.claude/skills/monitoring-alerting/SKILL.md** (`.claude/skills/monitoring-alerting/SKILL.md`)

Files in this skill

  • 0Chan-smc__claude-code-workflow-lab__claude__skills__frontend-dev-guidelines__SKILL.md15.1 KB
  • 17hz__nextjs-template__claude__skills__example-skill__SKILL.md316 B
  • 1ambda__dataops-platform__claude__skills__context-synthesis__SKILL.md3.5 KB
  • 1natsu172__dotfiles__claude__skills__git-analysis__SKILL.md5.4 KB
  • 1natsu172__dotfiles__claude__skills__github-pr-best-practices__SKILL.md7.7 KB
  • 23Maestro__prospect-pipeline__claude__skills__npid-fastapi-skill.md26.1 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-code-javascript__SKILL.md15.7 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-code-python__SKILL.md17.5 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-expression-syntax__SKILL.md9.4 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-mcp-tools-expert__SKILL.md12.5 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-node-configuration__SKILL.md16.6 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-workflow-patterns__SKILL.md11.2 KB
  • 3x-Projetos__claude-memory-framework__claude__skills__scientist__SKILL.md14.8 KB
  • 5MinFutures__futures-arena__claude__skills__migration-tracker__SKILL.md16.2 KB
  • 5MinFutures__futures-arena__claude__skills__planning-guidelines__SKILL.md11.8 KB
  • 92Bilal26__TaskPilotAI__claude__skills__assessment-builder__SKILL.md17.5 KB
  • 92Bilal26__TaskPilotAI__claude__skills__book-scaffolding__SKILL.md19.1 KB
  • 92Bilal26__TaskPilotAI__claude__skills__code-validation-sandbox__SKILL.md6.2 KB
  • 92Bilal26__TaskPilotAI__claude__skills__exercise-designer__SKILL.md18.1 KB
  • 92Bilal26__TaskPilotAI__claude__skills__learning-objectives__SKILL.md24.5 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.