{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-@l10n/ja/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"カスタムフォーマットを使用したログのインポート","description":"カスタムフォーマットのログをTreasure AIにインポートする方法を解説。パーサーの作成、ログのフィルタリング、JSONログの重要性について詳しく説明します。","siteUrl":"https://docs.treasure.ai","lang":"en-US","jsonLd":{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.treasure.ai/","name":"Treasure AI","url":"https://www.treasure.ai/","logo":"https://www.treasure.ai/hubfs/assets/images/logos/primary-logo.svg"},{"@type":"WebSite","@id":"https://docs.treasure.ai/#website","name":"Treasure AI Documentation","url":"https://docs.treasure.ai/","inLanguage":["en","ja"],"publisher":{"@id":"https://www.treasure.ai/"}}]},"llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"カスタムフォーマットを使用したログのインポート","__idx":0},"children":["カスタムフォーマットを使用したログのインポート"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["ログがカスタムフォーマットの場合、カスタムパーサーを作成する必要があります（",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://docs.fluentd.org/plugin-development#customizing-the-tail-input-plugin-parser"},"children":["手順"]},"）。パーサーを作成したら、ファイルを ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["/etc/td-agent/plugins/"]}," ディレクトリに配置します。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"一般的なパーサーの例","__idx":1},"children":["一般的なパーサーの例"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Treasure Dataは2つのパーサー例を提供しています：「URLパラメータ形式のキーバリューペア」と「ASCII文字区切り形式」です。どちらの形式もユーザーの間でかなり一般的です。"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"# URLパラメータ形式のキーバリューペア\nlast_name=smith&first_name=brian&age=22&state=CA\n\n# ASCII文字区切り形式。この場合、区切り文字は'|'です。\n# 通常、カラム名を注釈する別のファイルがあります\nsmith|brian|22|CA\n"},"children":[]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://gist.github.com/2565478"},"children":["URLパラメータ形式のキーバリューペア用カスタムパーサー"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://gist.github.com/2565493"},"children":["ASCII文字区切りログ用カスタムパーサー"]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["既存のログをテーリングすることは、Treasure Dataを始めるための簡単な方法です。すべてをJSONとしてログに記録することをお勧めします。",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://blog.treasuredata.com/blog/2012/04/26/log-everything-as-json/"},"children":["理由はこちら"]},"。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"レコードのフィルタリング","__idx":2},"children":["レコードのフィルタリング"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["ログをフィルタリングする必要がある場合（例：インプレッションをフィルタリングしてクリックだけを保持する）、",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://docs.fluentd.org/v1.0/articles/out_exec_filter"},"children":["exec-filterプラグイン"]},"が便利です。このプラグインは、STDINを入力、STDOUTを出力として受け取る別のスクリプトを起動し、それに応じてログをフィルタリングします。"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["以下は設定例です。"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"conf","header":{"controls":{"copy":{}}},"source":"<source>\n  type tail\n  path /path/to/the/file1\n  tag filter\n  format json\n  pos_file /var/log/td-agent/file1.pos\n</source>\n\n<match filter>\n  type exec_filter\n  command /usr/lib64/fluent/ruby/bin/ruby /etc/td-agent/filter.rb\n  in_format json  # takes a JSON string from STDIN\n  out_format json # generates a JSON string to STDOUT\n  tag_key tag     # The key for tags is \"tag\".\n  time_key time   # The key for timestamps is \"time\".\n</match>\n\n<match td.*.*>\n  type tdlog\n  endpoint api.treasuredata.com\n  apikey ...\n  auto_create_table\n  buffer_type file\n  buffer_path /var/log/td-agent/buffer/td\n  use_ssl true\n</match>\n","lang":"conf"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["/etc/td-agent/filter.rb"]}," は、以下の例に示すフィルタスクリプトです。このスクリプトは、フィールド \"field0\" が \"certain_value\" と等しいすべての行をフィルタリングします。エラーは ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["/var/log/td-agent/filter.rb.log"]}," に記録されます。"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"ruby","header":{"controls":{"copy":{}}},"source":"open('/var/log/td-agent/filter.rb.log', 'a') { |f|\n  f.puts \"-- begin --\"\n  begin\n    require 'json'\n    STDOUT.sync = true\n    while line = STDIN.gets\n      # parse\n      begin\n        h = JSON.parse line\n      rescue => e\n        next # broken line\n      end\n      # filter\n      # next if h[\"field0\"] == \"certain_value\"\n      # emit\n      h['tag'] = 'td.testdb.test_table'\n      puts h.to_json\n    end\n  rescue LoadError => e\n    f.puts e.to_s\n  end\n}\n","lang":"ruby"},"children":[]}]},"headings":[{"value":"カスタムフォーマットを使用したログのインポート","id":"カスタムフォーマットを使用したログのインポート","depth":1},{"value":"一般的なパーサーの例","id":"一般的なパーサーの例","depth":2},{"value":"レコードのフィルタリング","id":"レコードのフィルタリング","depth":2}],"frontmatter":{"seo":{"title":"カスタムフォーマットを使用したログのインポート","description":"カスタムフォーマットのログをTreasure AIにインポートする方法を解説。パーサーの作成、ログのフィルタリング、JSONログの重要性について詳しく説明します。"}},"lastModified":"2026-06-17T07:22:53.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/ja/int/logs-import-using-custom-format","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}