[Groonga-commit] ranguba/rroonga at 00b7ceb [master] Add Groonga::QueryLogger.rotate_threshold_size and setter

Back to archive index

Kouhei Sutou null+****@clear*****
Mon May 18 12:03:22 JST 2015


Kouhei Sutou	2015-05-18 12:03:22 +0900 (Mon, 18 May 2015)

  New Revision: 00b7ceb31992045afb7b2c4178e45d6289620514
  https://github.com/ranguba/rroonga/commit/00b7ceb31992045afb7b2c4178e45d6289620514

  Message:
    Add Groonga::QueryLogger.rotate_threshold_size and setter

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

  Modified: ext/groonga/rb-grn-query-logger.c (+58 -0)
===================================================================
--- ext/groonga/rb-grn-query-logger.c    2015-05-18 11:58:05 +0900 (cc183b4)
+++ ext/groonga/rb-grn-query-logger.c    2015-05-18 12:03:22 +0900 (87e4eed)
@@ -353,6 +353,58 @@ rb_grn_query_logger_s_set_path (VALUE klass, VALUE rb_path)
     return Qnil;
 }
 
+/*
+ * Gets the current rotate threshold size that is used by the default
+ * query logger.
+ *
+ * If the size is larger than 0, log rotate feature is enabled in the
+ * default query logger.
+ *
+ * @overload threshold
+ *   @return [Integer] The current rotate threshold size
+ *
+ * @since 5.0.2
+ */
+static VALUE
+rb_grn_query_logger_s_get_rotate_threshold_size (VALUE klass)
+{
+    return OFFT2NUM(grn_default_query_logger_get_rotate_threshold_size());
+}
+
+/*
+ * Sets the rotate threshold size that is used by the default query
+ * logger. If you're using custom query logger by {.register}, the
+ * rotate threshold size isn't used. Because it is for the default
+ * query logger.
+ *
+ * If you specify `0` as size, log rotation by the default query
+ * logger is disabled.
+ *
+ * The default rotate threshold size is 0. It means that log rotation
+ * is disabled by default.
+ *
+ * @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 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
+ *
+ * @since 5.0.2
+ */
+static VALUE
+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;
+}
+
 void
 rb_grn_init_query_logger (VALUE mGrn)
 {
@@ -383,6 +435,12 @@ rb_grn_init_query_logger (VALUE mGrn)
                                rb_grn_query_logger_s_get_path, 0);
     rb_define_singleton_method(cGrnQueryLogger, "path=",
                                rb_grn_query_logger_s_set_path, 1);
+    rb_define_singleton_method(cGrnQueryLogger, "rotate_threshold_size",
+                               rb_grn_query_logger_s_get_rotate_threshold_size,
+                               0);
+    rb_define_singleton_method(cGrnQueryLogger, "rotate_threshold_size=",
+                               rb_grn_query_logger_s_set_rotate_threshold_size,
+                               1);
 
     mGrnQueryLoggerFlags = rb_define_module_under(cGrnQueryLogger, "Flags");
 #define DEFINE_FLAG(NAME)                                       \

  Modified: test/test-query-logger.rb (+11 -0)
===================================================================
--- test/test-query-logger.rb    2015-05-18 11:58:05 +0900 (0868b0a)
+++ test/test-query-logger.rb    2015-05-18 12:03:22 +0900 (b5089fb)
@@ -18,10 +18,12 @@ class QueryLoggerTest < Test::Unit::TestCase
 
   def setup
     @default_log_path = Groonga::QueryLogger.path
+    @default_rotate_threshold_size = Groonga::QueryLogger.rotate_threshold_size
   end
 
   def teardown
     Groonga::QueryLogger.path = @default_log_path
+    Groonga::QueryLogger.rotate_threshold_size = @default_rotate_threshold_size
   end
 
   def test_reopen
@@ -135,4 +137,13 @@ class QueryLoggerTest < Test::Unit::TestCase
                    normalized_infos)
     end
   end
+
+  def test_rotate_threshold_size
+    Groonga::QueryLogger.unregister
+    Groonga::QueryLogger.path = @query_log_path.to_s
+    Groonga::QueryLogger.rotate_threshold_size = 10
+    assert_equal([], Dir.glob("#{@query_log_path}.*"))
+    Groonga::QueryLogger.log("command")
+    assert_not_equal([], Dir.glob("#{@query_log_path}.*"))
+  end
 end
-------------- next part --------------
HTML����������������������������...
Download 



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