場面
- nginxのログをtd-agentでtailするときにltsvにしたい
見るところ
-
log_formatの定義箇所
-
定義したlog_formatを呼び出す箇所
やってみる
stack settingsのcustom jsonいじるだけでできる。必要なのは2点。
node[:nginx][:log_format]["<my_log_format_name>"] = "<my_log_format_definition>"
に値を入れてlog_formatを定義する@application[:log_format] = ["<my_log_format_name>"]
に値を入れて、定義したlog_formatを利用する
{
"nginx": {
"log_format": {
"ltsv": "'time:$time_iso8601\\trequest_method:$request_method\\trequest_uri:$request_uri\\tstatus:$status\\tbody_bytes_sent:$body_bytes_sent\\trequest_time:$request_time\\thttp_referer:$http_referer\\thttp_user_agent:$http_user_agent\\thttp_x_forwarded_for:$http_x_forwarded_for'"
}
},
"deploy": {
"<my_application>": {
"log_format": ["ltsv"],
...
}
}
}
これでnginxのログをltsvで出力できる