[Groonga-commit] ranguba/rroonga at c0348fb [master] Add Groonga::Logger.max_level and max_level=

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Sep 8 18:34:11 JST 2015


Kouhei Sutou	2015-09-08 18:34:11 +0900 (Tue, 08 Sep 2015)

  New Revision: c0348fbf1d8803c08371e8227f3ea693164b9540
  https://github.com/ranguba/rroonga/commit/c0348fbf1d8803c08371e8227f3ea693164b9540

  Message:
    Add Groonga::Logger.max_level and max_level=

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

  Modified: ext/groonga/rb-grn-logger.c (+70 -0)
===================================================================
--- ext/groonga/rb-grn-logger.c    2015-09-08 17:50:02 +0900 (bdac115)
+++ ext/groonga/rb-grn-logger.c    2015-09-08 18:34:11 +0900 (6dbfd7b)
@@ -439,6 +439,70 @@ rb_grn_logger_s_reopen (VALUE klass)
 }
 
 /*
+ * @overload max_level(options={})
+ *   @param options [::Hash]
+ *   @option options :context [Groonga::Context] (Groonga::Context.default)
+ *     The context to be set logger.
+ *
+ *   @return [Symbol] The max level of the current logger.
+ *
+ * @since 5.0.5
+ */
+static VALUE
+rb_grn_logger_s_get_max_level (int argc, VALUE *argv, VALUE klass)
+{
+    VALUE rb_options;
+    VALUE rb_context;
+    grn_ctx *context;
+    grn_log_level max_level;
+
+    rb_scan_args(argc, argv, "01", &rb_options);
+    rb_grn_scan_options(rb_options,
+                        "context", &rb_context,
+                        NULL);
+    context = rb_grn_context_ensure(&rb_context);
+
+    max_level = grn_logger_get_max_level(context);
+    return GRNLOGLEVEL2RVAL(max_level);
+}
+
+/*
+ * Sets the max level of the current logger.
+ *
+ * @overload max_level=(max_level)
+ *   @param max_level [Symbol, String] The max level.
+ *
+ *   @return [void]
+ *
+ * @overload set_max_level(max_level, options={})
+ *   @param max_level [Symbol, String] The max level.
+ *   @param options [::Hash]
+ *   @option options :context [Groonga::Context] (Groonga::Context.default)
+ *     The context to be set logger.
+ *
+ *   @return [void]
+ *
+ * @since 5.0.5
+ */
+static VALUE
+rb_grn_logger_s_set_max_level (int argc, VALUE *argv, VALUE klass)
+{
+    VALUE rb_max_level;
+    VALUE rb_options;
+    VALUE rb_context;
+    grn_ctx *context;
+
+    rb_scan_args(argc, argv, "11", &rb_max_level, &rb_options);
+    rb_grn_scan_options(rb_options,
+                        "context", &rb_context,
+                        NULL);
+    context = rb_grn_context_ensure(&rb_context);
+
+    grn_logger_set_max_level(context, RVAL2GRNLOGLEVEL(rb_max_level));
+    return Qnil;
+}
+
+/*
  * Gets the current log path that is used by the default logger.
  *
  * @overload path
@@ -587,6 +651,12 @@ rb_grn_init_logger (VALUE mGrn)
                                rb_grn_logger_s_unregister, 0);
     rb_define_singleton_method(cGrnLogger, "reopen",
                                rb_grn_logger_s_reopen, 0);
+    rb_define_singleton_method(cGrnLogger, "max_level",
+                               rb_grn_logger_s_get_max_level, -1);
+    rb_define_singleton_method(cGrnLogger, "max_level=",
+                               rb_grn_logger_s_set_max_level, -1);
+    rb_define_singleton_method(cGrnLogger, "set_max_level",
+                               rb_grn_logger_s_set_max_level, -1);
     rb_define_singleton_method(cGrnLogger, "path",
                                rb_grn_logger_s_get_path, 0);
     rb_define_singleton_method(cGrnLogger, "path=",

  Modified: test/test-logger.rb (+6 -0)
===================================================================
--- test/test-logger.rb    2015-09-08 17:50:02 +0900 (6230fb0)
+++ test/test-logger.rb    2015-09-08 18:34:11 +0900 (7fa0c07)
@@ -37,6 +37,12 @@ class LoggerTest < Test::Unit::TestCase
     assert_true(@log_path.exist?)
   end
 
+  def test_max_level
+    assert_equal(:notice, Groonga::Logger.max_level)
+    Groonga::Logger.max_level = :debug
+    assert_equal(:debug, Groonga::Logger.max_level)
+  end
+
   sub_test_case ".log" do
     test "no options" do
       messages = []
-------------- next part --------------
HTML����������������������������...
Download 



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