Kentaro Hayashi
null+****@clear*****
Mon Sep 25 17:26:30 JST 2017
Kentaro Hayashi 2017-09-25 17:26:30 +0900 (Mon, 25 Sep 2017) New Revision: 126e870666358e97aa1e4567cb84d005523db4fb https://github.com/groonga/fluent-plugin-groonga-log/commit/126e870666358e97aa1e4567cb84d005523db4fb Merged fcfa394: Merge pull request #2 from kenhys/use-groonga-log Message: Use groonga-log library Modified files: fluent-plugin-groonga-log.gemspec lib/fluent/plugin/parser_groonga_log.rb test/plugin/test_parser_groonga_log.rb Modified: fluent-plugin-groonga-log.gemspec (+1 -0) =================================================================== --- fluent-plugin-groonga-log.gemspec 2017-09-26 15:06:37 +0900 (6c410f1) +++ fluent-plugin-groonga-log.gemspec 2017-09-25 17:26:30 +0900 (2e5df08) @@ -24,4 +24,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "rake", "~> 12.0" spec.add_development_dependency "test-unit", "~> 3.0" spec.add_runtime_dependency "fluentd", [">= 0.14.10", "< 2"] + spec.add_runtime_dependency "groonga-log" end Modified: lib/fluent/plugin/parser_groonga_log.rb (+6 -33) =================================================================== --- lib/fluent/plugin/parser_groonga_log.rb 2017-09-26 15:06:37 +0900 (ed2b9ed) +++ lib/fluent/plugin/parser_groonga_log.rb 2017-09-25 17:26:30 +0900 (1e7c7af) @@ -14,17 +14,17 @@ # limitations under the License. require "fluent/plugin/parser" +require "groonga-log/parser" module Fluent module Plugin class GroongaLogParser < Fluent::Plugin::Parser Fluent::Plugin.register_parser("groonga_log", self) - REGEXP = - /\A(?<year>\d{4})-(?<month>\d\d)-(?<day>\d\d) (?<hour>\d\d):(?<minutes>\d\d):(?<seconds>\d\d)\.(?<micro_seconds>\d+)\|(?<log_level>.)\|(?<context_id>.+?)\|(?<message>.*)/ def initialize super @mutex = Mutex.new + @parser = GroongaLog::Parser.new end def configure(conf) @@ -36,38 +36,11 @@ module Fluent end def parse(text) - m = REGEXP.match(text) - unless m - yield nil, nil - return + @parser.parse(text) do |statistic| + timestamp = statistic.delete("timestamp") + event_time = Fluent::EventTime.from_time(timestamp) + yield event_time, statistic end - - year = m['year'] - month = m['month'] - day = m['day'] - hour = m['hour'] - minutes = m['minutes'] - seconds = m['seconds'] - micro_seconds = m['micro_seconds'] - log_level = m['log_level'] - context_id = m['context_id'] - message = m['message'] - time = Fluent::Engine.now - - record = { - "year" => year, - "month" => month, - "day" => day, - "hour" => hour, - "minutes" => minutes, - "seconds" => seconds, - "micro_seconds" => micro_seconds, - "log_level" => log_level, - "context_id" => context_id, - "message" => message, - } - - yield time, record end end end Modified: test/plugin/test_parser_groonga_log.rb (+8 -8) =================================================================== --- test/plugin/test_parser_groonga_log.rb 2017-09-26 15:06:37 +0900 (b612924) +++ test/plugin/test_parser_groonga_log.rb 2017-09-25 17:26:30 +0900 (d0e0b5e) @@ -6,14 +6,14 @@ class GroongaLogParserTest < Test::Unit::TestCase Fluent::Test.setup @parser = create_driver({}) @expected = { - "year" => "2017", - "month" => "07", - "day" => "19", - "hour" => "14", - "minutes" => "41", - "seconds" => "05", - "micro_seconds" => "663978", - "log_level" => "n", + "year" => 2017, + "month" => 7, + "day" => 19, + "hour" => 14, + "minutes" => 41, + "seconds" => 5, + "micro_seconds" => 663978, + "log_level" => :notice, "context_id" => "18c61700", "message" => "spec:2:update:Object:32(type):8", } -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20170925/32b91cfc/attachment-0001.htm