LoginSignup
5
3

More than 3 years have passed since last update.

構造化ログとは?

Posted at

概要

json形式(場合によっては他の形式も)を利用して構造化されたログのこと。
普通のテキストログが人間に取って読みやすいのに対して、構造化ログは機械にとって読みやすい。

例えばこれが

<6>Feb 28 12:00:00 192.168.0.1 fluentd[11111]: [error] Syslog test

こうなる

    jsonPayload: {
        "pri": "6",
        "host": "192.168.0.1",
        "ident": "fluentd",
        "pid": "11111",
        "message": "[error] Syslog test"
    }

全体としてはこんな感じ。


 {
         insertId:  "1m9mtk4g3mwilhp"
         jsonPayload: {
          code:  "structured-log-code"
          message:  "This is a log from the log file at test-structured-log.log"
         }
         labels: {
          compute.googleapis.com/resource_name:  "add-structured-log-resource"
         }
         logName:  "projects/my-sample-project-12345/logs/structured-log"
         receiveTimestamp:  "2018-03-21T01:53:41.118200931Z"
         resource: {
          labels: {
           instance_id:  "5351724540900470204"
           project_id:  "my-sample-project-12345"
           zone:  "us-central1-c"
          }
          type:  "gce_instance"
         }
         timestamp:  "2018-03-21T01:53:39.071920609Z"
        }

普通のログに比べて構造化ログが優秀なとこ

  • jsonなのでテキストフォーマットよりも付加的な情報を意味のある形で追加しやすい
  • 様々なツールと容易に連携できる
    • 事前に想定していなかったユースケースのときなど特に強力
  • 検索性能が高い

構造化ログのデメリット

  • 容量が少し多くなる

関連してよく使用されるサービス・ツール

  • fluentd
  • rsyslog
  • stackdriver logging

参考

https://cloud.google.com/logging/docs/structured-logging?hl=ja
https://pod.hatenablog.com/entry/2017/05/20/232522
https://qiita.com/yuya_takeyama/items/825ceb6a2f4ab251745c#fnref1
https://www.wantedly.com/companies/quipper/post_articles/161707

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3