[Groonga-commit] groonga/groonga at ec54710 [master] mrb: add Loggable and QueryLoggable

Back to archive index
Kouhei Sutou null+****@clear*****
Mon May 13 15:48:37 JST 2019


Kouhei Sutou	2019-05-13 15:48:37 +0900 (Mon, 13 May 2019)

  Revision: ec54710848fb6f5b07f7c6ae056571939f4ec59a
  https://github.com/groonga/groonga/commit/ec54710848fb6f5b07f7c6ae056571939f4ec59a

  Message:
    mrb: add Loggable and QueryLoggable

  Added files:
    lib/mrb/scripts/loggable.rb
    lib/mrb/scripts/query_loggable.rb
  Modified files:
    lib/mrb/scripts/command.rb
    lib/mrb/scripts/command_line/grndb.rb
    lib/mrb/scripts/initialize/pre.rb
    lib/mrb/scripts/sources.am
    plugins/sharding/logical_count.rb
    plugins/sharding/logical_range_filter.rb
    plugins/sharding/logical_select.rb

  Modified: lib/mrb/scripts/command.rb (+3 -4)
===================================================================
--- lib/mrb/scripts/command.rb    2019-05-13 13:33:13 +0900 (26dfe68cd)
+++ lib/mrb/scripts/command.rb    2019-05-13 15:48:37 +0900 (b7f077d2f)
@@ -1,5 +1,8 @@
 module Groonga
   class Command
+    include Loggable
+    include QueryLoggable
+
     @@classes = {}
     class << self
       def register_class(name, klass)
@@ -20,10 +23,6 @@ module Groonga
       @writer ||= context.writer
     end
 
-    def query_logger
-      @query_logger ||= context.query_logger
-    end
-
     def cache_key(input)
       nil
     end

  Modified: lib/mrb/scripts/command_line/grndb.rb (+2 -1)
===================================================================
--- lib/mrb/scripts/command_line/grndb.rb    2019-05-13 13:33:13 +0900 (b3864eab3)
+++ lib/mrb/scripts/command_line/grndb.rb    2019-05-13 15:48:37 +0900 (858bc0f64)
@@ -451,6 +451,8 @@ module Groonga
       end
 
       class Recoverer
+        include Loggable
+
         attr_writer :database
         attr_writer :force_truncate
         attr_writer :force_lock_clear
@@ -489,7 +491,6 @@ module Groonga
         end
 
         def truncate_broken_object(object)
-          logger =****@conte*****
           name = object.name
           object_path = object.path
           object_dirname = File.dirname(object_path)

  Modified: lib/mrb/scripts/initialize/pre.rb (+3 -0)
===================================================================
--- lib/mrb/scripts/initialize/pre.rb    2019-05-13 13:33:13 +0900 (99300d11a)
+++ lib/mrb/scripts/initialize/pre.rb    2019-05-13 15:48:37 +0900 (18bee0e3e)
@@ -1,3 +1,6 @@
 require "backtrace_entry"
 
 require "operator"
+
+require "loggable"
+require "query_loggable"

  Added: lib/mrb/scripts/loggable.rb (+8 -0) 100644
===================================================================
--- /dev/null
+++ lib/mrb/scripts/loggable.rb    2019-05-13 15:48:37 +0900 (2c949ebe1)
@@ -0,0 +1,8 @@
+module Groonga
+  module Loggable
+    private
+    def logger
+      Context.instance.logger
+    end
+  end
+end

  Added: lib/mrb/scripts/query_loggable.rb (+8 -0) 100644
===================================================================
--- /dev/null
+++ lib/mrb/scripts/query_loggable.rb    2019-05-13 15:48:37 +0900 (513680d08)
@@ -0,0 +1,8 @@
+module Groonga
+  module QueryLoggable
+    private
+    def query_logger
+      Context.instance.query_logger
+    end
+  end
+end

  Modified: lib/mrb/scripts/sources.am (+2 -0)
===================================================================
--- lib/mrb/scripts/sources.am    2019-05-13 13:33:13 +0900 (7d6c659b4)
+++ lib/mrb/scripts/sources.am    2019-05-13 15:48:37 +0900 (2f1ea60ea)
@@ -21,10 +21,12 @@ RUBY_SCRIPT_FILES =				\
 	index_info.rb				\
 	labeled_arguments.rb			\
 	locale_output.rb			\
+	loggable.rb				\
 	logger.rb				\
 	object.rb				\
 	operator.rb				\
 	plugin_loader.rb			\
+	query_loggable.rb			\
 	query_logger.rb				\
 	record.rb				\
 	require.rb				\

  Modified: plugins/sharding/logical_count.rb (+7 -6)
===================================================================
--- plugins/sharding/logical_count.rb    2019-05-13 13:33:13 +0900 (55084eb5f)
+++ plugins/sharding/logical_count.rb    2019-05-13 15:48:37 +0900 (604d11b8e)
@@ -69,8 +69,9 @@ module Groonga
       end
 
       class Counter
+        include Loggable
+
         def initialize(input, target_range)
-          @logger = Context.instance.logger
           @filter = input[:filter]
           @post_filter = input[:post_filter]
           @dynamic_columns = DynamicColumns.parse(input)
@@ -136,11 +137,11 @@ module Groonga
             message << "[select]"
           end
           message << " <#{table_name}>: #{reason}"
-          @logger.log(Logger::Level::DEBUG,
-                      __FILE__,
-                      line,
-                      method.to_s,
-                      message)
+          logger.log(Logger::Level::DEBUG,
+                     __FILE__,
+                     line,
+                     method.to_s,
+                     message)
         end
 
         def prepare_contexts

  Modified: plugins/sharding/logical_range_filter.rb (+13 -11)
===================================================================
--- plugins/sharding/logical_range_filter.rb    2019-05-13 13:33:13 +0900 (a80b7825f)
+++ plugins/sharding/logical_range_filter.rb    2019-05-13 15:48:37 +0900 (0b8db30ec)
@@ -261,6 +261,7 @@ module Groonga
 
       class Window
         include Comparable
+        include Loggable
 
         attr_reader :unit
         attr_reader :step
@@ -326,11 +327,11 @@ module Groonga
                 message = "[logical_range_filter][window] "
                 message << "<#{@shard.table_name}>: "
                 message << inspect_range(current_min, current_max)
-                Context.instance.logger.log(Logger::Level::DEBUG,
-                                            __FILE__,
-                                            __LINE__,
-                                            __method__.to_s,
-                                            message)
+                logger.log(Logger::Level::DEBUG,
+                           __FILE__,
+                           __LINE__,
+                           __method__.to_s,
+                           message)
                 yield(windowed_table)
               end
               current_min = next_min
@@ -494,6 +495,8 @@ module Groonga
       end
 
       class ShardExecutor
+        include Loggable
+
         attr_reader :shard
         attr_writer :previous_executor
         attr_writer :next_executor
@@ -634,12 +637,11 @@ module Groonga
           end
           message << "<#{@shard.table_name}>: "
           message << reason
-          Context.instance.logger.log(Logger::Level::DEBUG,
-                                      __FILE__,
-                                      line,
-                                      method.to_s,
-                                      message)
-
+          logger.log(Logger::Level::DEBUG,
+                     __FILE__,
+                     line,
+                     method.to_s,
+                     message)
           use
         end
 

  Modified: plugins/sharding/logical_select.rb (+2 -4)
===================================================================
--- plugins/sharding/logical_select.rb    2019-05-13 13:33:13 +0900 (ce29ef7d3)
+++ plugins/sharding/logical_select.rb    2019-05-13 15:48:37 +0900 (67d215231)
@@ -739,6 +739,8 @@ module Groonga
       end
 
       class ShardExecutor
+        include QueryLoggable
+
         def initialize(context, shard, shard_range)
           @context = context
           @shard = shard
@@ -891,10 +893,6 @@ module Groonga
 
           @shard_results << [self, result_set, condition]
         end
-
-        def query_logger
-          Context.instance.query_logger
-        end
       end
     end
   end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190513/aad4eb6c/attachment-0001.html>


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