[Groonga-commit] groonga/groonga-log at bf6804c [master] Support Mroonga style Groonga log

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Jul 30 16:47:43 JST 2018


Kouhei Sutou	2018-07-30 16:47:43 +0900 (Mon, 30 Jul 2018)

  New Revision: bf6804c406f7de5e27f85e45464e6ee47ceb3022
  https://github.com/groonga/groonga-log/commit/bf6804c406f7de5e27f85e45464e6ee47ceb3022

  Message:
    Support Mroonga style Groonga log

  Modified files:
    lib/groonga-log/entry.rb
    lib/groonga-log/parser.rb
    test/test-input.rb
    test/test-parser.rb

  Modified: lib/groonga-log/entry.rb (+1 -0)
===================================================================
--- lib/groonga-log/entry.rb    2018-03-08 11:51:51 +0900 (cbb870b)
+++ lib/groonga-log/entry.rb    2018-07-30 16:47:43 +0900 (368edea)
@@ -18,6 +18,7 @@ module GroongaLog
   class Entry < Struct.new(:timestamp,
                            :log_level,
                            :pid,
+                           :thread_id,
                            :message)
   end
 end

  Modified: lib/groonga-log/parser.rb (+3 -2)
===================================================================
--- lib/groonga-log/parser.rb    2018-03-08 11:51:51 +0900 (d4398d0)
+++ lib/groonga-log/parser.rb    2018-07-30 16:47:43 +0900 (fb69f25)
@@ -25,8 +25,8 @@ module GroongaLog
       /\A(?<year>\d{4})-(?<month>\d\d)-(?<day>\d\d)
           \ (?<hour>\d\d):(?<minute>\d\d):(?<second>\d\d)\.(?<micro_second>\d+)
           \|(?<log_level>.)
-          \|(?:(?<pid>\d+):)?
-          \ (?<message>[^\r\n]*)/x
+          \|(?:(?:(?<pid>\d+):|(?<thread_id>[\da-fA-F]+)\|))?
+          \ ?(?<message>[^\r\n]*)/x
     PATH_TIMESTAMP_PATTERN = /(\d{4})-(\d{2})-(\d{2})-
                               (\d{2})-(\d{2})-(\d{2})-(\d{6})
                               (?:\.(?:gz|zip))?\z/xi
@@ -85,6 +85,7 @@ module GroongaLog
         entry.log_level = log_level_to_symbol(match_data[:log_level])
         pid = match_data[:pid]
         entry.pid = Integer(pid, 10) if pid
+        entry.thread_id = match_data[:thread_id]
         entry.message = match_data[:message]
         yield entry
       end

  Modified: test/test-input.rb (+6 -0)
===================================================================
--- test/test-input.rb    2018-03-08 11:51:51 +0900 (6af2bd0)
+++ test/test-input.rb    2018-07-30 16:47:43 +0900 (42d05e1)
@@ -29,12 +29,14 @@ class ParserTest < Test::Unit::TestCase
         :timestamp => Time.local(2018, 1, 15, 15, 1, 23, 305389),
         :log_level => :notice,
         :pid => nil,
+        :thread_id => nil,
         :message => "grn_init: <7.1.0-1-gef1bd38>",
       },
       {
         :timestamp => Time.local(2018, 1, 15, 15, 1, 23, 712541),
         :log_level => :notice,
         :pid => nil,
+        :thread_id => nil,
         :message => "grn_fin (0)",
       },
     ]
@@ -48,12 +50,14 @@ class ParserTest < Test::Unit::TestCase
         :timestamp => Time.local(2018, 1, 15, 15, 1, 23, 305389),
         :log_level => :notice,
         :pid => nil,
+        :thread_id => nil,
         :message => "grn_init: <7.1.0-1-gef1bd38>",
       },
       {
         :timestamp => Time.local(2018, 1, 15, 15, 1, 23, 712541),
         :log_level => :notice,
         :pid => nil,
+        :thread_id => nil,
         :message => "grn_fin (0)",
       },
     ]
@@ -67,12 +71,14 @@ class ParserTest < Test::Unit::TestCase
         :timestamp => Time.local(2018, 1, 15, 15, 1, 23, 305389),
         :log_level => :notice,
         :pid => nil,
+        :thread_id => nil,
         :message => "grn_init: <7.1.0-1-gef1bd38>",
       },
       {
         :timestamp => Time.local(2018, 1, 15, 15, 1, 23, 712541),
         :log_level => :notice,
         :pid => nil,
+        :thread_id => nil,
         :message => "grn_fin (0)",
       },
     ]

  Modified: test/test-parser.rb (+17 -0)
===================================================================
--- test/test-parser.rb    2018-03-08 11:51:51 +0900 (2511239)
+++ test/test-parser.rb    2018-07-30 16:47:43 +0900 (c533a56)
@@ -23,6 +23,7 @@ class InputTest < Test::Unit::TestCase
         :timestamp => Time.local(2017, 7, 19, 14, 9, 5, 663978),
         :log_level => :notice,
         :pid => 29,
+        :thread_id => nil,
         :message => "spec:2:update:Object:32(type):8",
       }
       entries = parse(<<-LOG)
@@ -37,6 +38,7 @@ class InputTest < Test::Unit::TestCase
         :timestamp => Time.local(2017, 7, 19, 14, 9, 5, 663978),
         :log_level => :notice,
         :pid => nil,
+        :thread_id => nil,
         :message => "spec:2:update:Object:32(type):8",
       }
       entries = parse(<<-LOG)
@@ -45,6 +47,21 @@ class InputTest < Test::Unit::TestCase
       assert_equal([raw_entry],
                    entries.collect(&:to_h))
     end
+
+    def test_with_thread_id
+      raw_entry = {
+        :timestamp => Time.local(2017, 7, 19, 14, 9, 5, 663978),
+        :log_level => :notice,
+        :pid => nil,
+        :thread_id => "528b9700",
+        :message => "spec:2:update:Object:32(type):8",
+      }
+      entries = parse(<<-LOG)
+2017-07-19 14:09:05.663978|n|528b9700|spec:2:update:Object:32(type):8
+      LOG
+      assert_equal([raw_entry],
+                   entries.collect(&:to_h))
+    end
   end
 
   def test_log_level
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180730/c19ffb9c/attachment-0001.htm 



More information about the Groonga-commit mailing list
Back to archive index