

# プロセッサの一般的なユースケース
<a name="processor-examples"></a>

プロセッサの組み合わせに関する一般的なシナリオと設定例を次に示します。

**Example ログ形式を標準化し、メタデータを追加する**  
JSON ログを解析し、フィールド名を標準化して、環境情報を追加します。  

```
processor:
  - parse_json: {}
  - rename_keys:
      entries:
        - from_key: "timestamp"
          to_key: "@timestamp"
        - from_key: "log_level"
          to_key: "level"
  - add_entries:
      entries:
        - key: "environment"
          value: "production"
        - key: "application"
          value: "payment-service"
```

**Example フィールド値をクリーンアップして正規化する**  
ステータスコードを標準化し、機密データを削除します。  

```
processor:
  - uppercase_string:
      with_keys: ["status", "method"]
  - delete_entries:
      with_keys: ["credit_card", "password"]
  - substitute_string:
      entries:
        - source: "status"
          from: "SUCCESS"
          to: "OK"
```

**Example 特定のフィールドを抽出および変換する**  
分析用のユーザー情報と形式を抽出します。  

```
processor:
  - extract_value:
      entries:
        - source: "user_agent"
          target: "browser"
          from: "(?<browser>Chrome|Firefox|Safari)"
          to: "${browser}"
  - lowercase_string:
      with_keys: ["browser"]
  - move_keys:
      entries:
        - from_key: "browser"
          to_key: "user_data.browser"
```

**Example エントリレベルの条件を使用した条件付き処理**  
エントリレベルの `when` 条件を使用して、ログの重要度に基づいて異なるメタデータを追加します:  

```
processor:
  - add_entries:
      entries:
        - key: "alert_level"
          value: "critical"
          when: "log.level == 'ERROR'"
        - key: "alert_level"
          value: "info"
          when_else: "log.level == 'ERROR'"
```

**Example 不要なログエントリを削除する**  
サードパーティーのソースからデバッグとトレースのログエントリをフィルターで除外して、ノイズとストレージのコストを削減します。  

```
processor:
  - drop_events:
      when: "log.level in {'DEBUG', 'TRACE'}"
      handle_expression_failure: "skip"
```

**Example delete\$1entries を使用したプロセッサレベルの条件付き**  
環境が本番環境の場合にのみ、機密フィールドを削除します。  

```
processor:
  - delete_entries:
      with_keys: ["password", "api_key", "ssn"]
      when: "environment in {'prod', 'staging'}"
```