Fluent Bit でデバッグログを有効にする方法を教えてください

2023.10.19

困っていた内容

FireLens と Fluent Bit を使ってコンテナのログを CloudWatch Logs に転送しています。
トラブルシューティングのため、Fluent Bit (log_router)のログレベルを debug に変更したいです。
変更方法を教えてください。

どう対応すればいいの?

タスク定義の環境変数でFLB_LOG_LEVEL=debugを設定してください。

タスク定義の例

"environment": [
    {
        "name": "FLB_LOG_LEVEL",
        "value": "debug"
    }
],

Fluent Bit でデバッグログを有効にしたい場合、二つの選択肢があります。

  1. 環境変数でFLB_LOG_LEVEL=debugを指定する
  2. 設定ファイルのSERVICEセクションで指定する

カスタム設定ファイルがない場合、タスク定義の環境変数でFLB_LOG_LEVEL=debugを指定すると、最小限の手間でデバッグログを有効にできます。

既にカスタム設定ファイルを使用している場合などは、SERVICEセクションにLog_Levelの設定を追加することで、デバッグログを有効にできます。

カスタム設定ファイルの設定例

[SERVICE]
    Log_Level debug

環境変数で有効化をやってみた

デバッグログを有効にするタスク定義を開き、「新しいリビジョンを作成」を選択します。

ログルーティングコンテナのセクションで、「環境変数を追加」をクリックします。

次の値を指定します。

  • キー:FLB_LOG_LEVEL
  • 値のタイプ:値
  • 値:debug

デバッグログが CloudWatch Logs に出力されるように、ログ収集が有効になっていることを確認し、タスク定義を作成します。

タスク定義が正常に作成されたことを確認したら、ECS サービスなどの設定を更新し、作成したタスク定義でタスクを実行してください。

ログのサンプル

message
Fluent Bit v1.9.10
* Copyright (C) 2015-2022 The Fluent Bit Authors
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io
[2023/10/01 01:01:01] [ info] Configuration:
[2023/10/01 01:01:01] [ info]  flush time     | 1.000000 seconds
[2023/10/01 01:01:01] [ info]  grace          | 5 seconds
[2023/10/01 01:01:01] [ info]  daemon         | 0
[2023/10/01 01:01:01] [ info] ___________
[2023/10/01 01:01:01] [ info]  inputs:
[2023/10/01 01:01:01] [ info]      tcp
[2023/10/01 01:01:01] [ info]      forward
[2023/10/01 01:01:01] [ info]      forward
[2023/10/01 01:01:01] [ info] ___________
[2023/10/01 01:01:01] [ info]  filters:
[2023/10/01 01:01:01] [ info]      record_modifier.0
[2023/10/01 01:01:01] [ info] ___________
[2023/10/01 01:01:01] [ info]  outputs:
[2023/10/01 01:01:01] [ info]      null.0
[2023/10/01 01:01:01] [ info]      cloudwatch.1
[2023/10/01 01:01:01] [ info] ___________
[2023/10/01 01:01:01] [ info]  collectors:
"AWS for Fluent Bit Container Image Version 2.31.12.20230911time=""2023-10-01T01:01:01Z"" level=debug msg=""A new higher performance CloudWatch Logs plugin has been released; you are using the old plugin. Check out the new plugin's documentation and determine if you can migrate.
https://docs.fluentbit.io/manual/pipeline/outputs/cloudwatch"" func=""main.FLBPluginInit()"" file=""fluent-bit-cloudwatch.go:150"""

参考資料

Enable Debug Logging

Many Fluent Bit problems can be easily understood once you have full log output. Also, if you want help from the aws-for-fluent-bit team, we generally request/require debug log output.

The log level for Fluent Bit can be set in the Service section, or by setting the environment variable FLB_LOG_LEVEL=debug.

log_level

Set the logging verbosity level. Allowed values are: off, error, warn, info, debug and trace. Values are accumulative, e.g: if 'debug' is set, it will include error, warning, info and debug. Note that trace mode is only available if Fluent Bit was built with the WITH_TRACE option enabled.