[Groonga-commit] ranguba/rroonga at 0936471 [master] Add QueryLogger.flags and flags=

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Jan 30 15:50:06 JST 2018


Kouhei Sutou	2018-01-30 15:50:06 +0900 (Tue, 30 Jan 2018)

  New Revision: 0936471ab1fb17ebf11ab13888de889e9ba1528f
  https://github.com/ranguba/rroonga/commit/0936471ab1fb17ebf11ab13888de889e9ba1528f

  Message:
    Add QueryLogger.flags and flags=

  Modified files:
    ext/groonga/rb-grn-query-logger.c
    lib/groonga/query-logger.rb
    test/test-query-logger.rb

  Modified: ext/groonga/rb-grn-query-logger.c (+55 -6)
===================================================================
--- ext/groonga/rb-grn-query-logger.c    2018-01-30 15:49:58 +0900 (d3e439cf)
+++ ext/groonga/rb-grn-query-logger.c    2018-01-30 15:50:06 +0900 (66de7293)
@@ -1,6 +1,6 @@
 /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /*
-  Copyright (C) 2012-2015  Kouhei Sutou <kou �� clear-code.com>
+  Copyright (C) 2012-2018  Kouhei Sutou <kou �� clear-code.com>
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -390,10 +390,11 @@ rb_grn_query_logger_s_get_rotate_threshold_size (VALUE klass)
  *   Groonga::QueryLogger.rotate_threshold_size = 0
  *
  * @overload rotate_threshold_size=(size)
- *   @param size [Integer] The log path for the default query logger.
- *     If nil is specified, log rotate by the default query logger is
- *     disabled.
- *   @return void
+ *   @param size [Integer] The rotate threshold size for the default
+ *     query logger. If `nil` is specified, log rotate by the default
+ *     query logger is disabled.
+ *
+ *   @return `size` itself.
  *
  * @since 5.0.2
  */
@@ -402,7 +403,49 @@ rb_grn_query_logger_s_set_rotate_threshold_size (VALUE klass, VALUE rb_size)
 {
     grn_default_query_logger_set_rotate_threshold_size(NUM2OFFT(rb_size));
 
-    return Qnil;
+    return rb_size;
+}
+
+/*
+ * Gets the current flags that are used by the default query logger.
+ *
+ * @overload flags
+ *   @return [Integer] The current flags
+ *
+ * @since 7.1.1
+ */
+static VALUE
+rb_grn_query_logger_s_get_flags (VALUE klass)
+{
+    return UINT2NUM(grn_default_query_logger_get_flags());
+}
+
+/*
+ * Sets the flags that are used by the default query logger. If you're
+ * using custom query logger by {.register}, the flags aren't
+ * used. Because it is for the default query logger.
+ *
+ * @example Changes the rotate threshold size for the default query logger
+ *   Groonga::QueryLogger.rotate_threshold_size = 1 * 1024 * 1024 # 1MiB
+ *
+ * @example Disables log ration by the default query logger
+ *   Groonga::QueryLogger.rotate_threshold_size = 0
+ *
+ * @overload flags=(flags)
+ *   @param flags [Integer] The flags for the default query logger.
+ *   @return void
+ *
+ * @since 7.1.1
+ */
+static VALUE
+rb_grn_query_logger_s_set_flags (VALUE klass, VALUE rb_flags)
+{
+    VALUE rb_parsed_flags;
+
+    rb_parsed_flags = rb_funcall(mGrnQueryLoggerFlags, id_parse, 1, rb_flags);
+    grn_default_query_logger_set_flags(NUM2UINT(rb_parsed_flags));
+
+    return rb_flags;
 }
 
 void
@@ -441,6 +484,12 @@ rb_grn_init_query_logger (VALUE mGrn)
     rb_define_singleton_method(cGrnQueryLogger, "rotate_threshold_size=",
                                rb_grn_query_logger_s_set_rotate_threshold_size,
                                1);
+    rb_define_singleton_method(cGrnQueryLogger, "flags",
+                               rb_grn_query_logger_s_get_flags,
+                               0);
+    rb_define_singleton_method(cGrnQueryLogger, "flags=",
+                               rb_grn_query_logger_s_set_flags,
+                               1);
 
     mGrnQueryLoggerFlags = rb_define_module_under(cGrnQueryLogger, "Flags");
 #define DEFINE_FLAG(NAME)                                       \

  Modified: lib/groonga/query-logger.rb (+1 -1)
===================================================================
--- lib/groonga/query-logger.rb    2018-01-30 15:49:58 +0900 (0d9624e5)
+++ lib/groonga/query-logger.rb    2018-01-30 15:50:06 +0900 (dd9af4cc)
@@ -41,7 +41,7 @@ module Groonga
       class << self
         # TODO: Document me.
         def parse(input, base_flags=nil)
-          base_flags |= Flags::NONE
+          base_flags ||= Flags::NONE
           case input
           when nil
             base_flags

  Modified: test/test-query-logger.rb (+10 -0)
===================================================================
--- test/test-query-logger.rb    2018-01-30 15:49:58 +0900 (c1362455)
+++ test/test-query-logger.rb    2018-01-30 15:50:06 +0900 (e9bef8ab)
@@ -19,11 +19,13 @@ class QueryLoggerTest < Test::Unit::TestCase
   def setup
     @default_log_path = Groonga::QueryLogger.path
     @default_rotate_threshold_size = Groonga::QueryLogger.rotate_threshold_size
+    @default_flags = Groonga::QueryLogger.flags
   end
 
   def teardown
     Groonga::QueryLogger.path = @default_log_path
     Groonga::QueryLogger.rotate_threshold_size = @default_rotate_threshold_size
+    Groonga::QueryLogger.flags = @default_flags
   end
 
   def test_reopen
@@ -147,4 +149,12 @@ class QueryLoggerTest < Test::Unit::TestCase
     Groonga::QueryLogger.log("command")
     assert_not_equal([], Dir.glob("#{@query_log_path}.*"))
   end
+
+  sub_test_case("flags") do
+    test("name") do
+      Groonga::QueryLogger.flags = :command
+      assert_equal(Groonga::QueryLogger::Flags::COMMAND,
+                   Groonga::QueryLogger.flags)
+    end
+  end
 end
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180130/6e1825fb/attachment-0001.htm 



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