[Groonga-commit] ranguba/rroonga at af7d6be [add-logger-flags] Add Groonga::Logger.flags and Groonga::Logger.flags=

Back to archive index

Masafumi Yokoyama null+****@clear*****
Mon Dec 12 21:10:55 JST 2016


Masafumi Yokoyama	2016-12-12 21:10:55 +0900 (Mon, 12 Dec 2016)

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

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

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

  Modified: ext/groonga/rb-grn-logger.c (+47 -0)
===================================================================
--- ext/groonga/rb-grn-logger.c    2016-12-12 19:40:33 +0900 (b39de5b)
+++ ext/groonga/rb-grn-logger.c    2016-12-12 21:10:55 +0900 (5dfb458)
@@ -1,6 +1,7 @@
 /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /*
   Copyright (C) 2009-2015  Kouhei Sutou <kou �� clear-code.com>
+  Copyright (C) 2016  Masafumi Yokoyama <yokoyama �� 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
@@ -548,6 +549,48 @@ rb_grn_logger_s_set_path (VALUE klass, VALUE rb_path)
 }
 
 /*
+ * Gets the current log flags that is used by the default logger.
+ *
+ * @overload flags
+ *   @return [Integer] The current log flags.
+ *
+ * @since 6.1.1
+ */
+static VALUE
+rb_grn_logger_s_get_flags (VALUE klass)
+{
+    int flags = 0;
+    VALUE rb_flags;
+
+    flags = grn_default_logger_get_flags();
+    rb_flags = UINT2NUM(flags);
+
+    return rb_flags;
+}
+
+/*
+ * Sets the log flags that is used by the default logger.
+ *
+ * @overload flags=(flags)
+ *   @param flags [Integer] The log flags for the default logger.
+ *   @return void
+ *
+ * @since 6.1.1
+ */
+static VALUE
+rb_grn_logger_s_set_flags (VALUE klass, VALUE rb_flags)
+{
+    int flags = 0;
+
+    if (!NIL_P(rb_flags)) {
+        flags = NUM2UINT(rb_flags);
+    }
+    grn_default_logger_set_flags(flags);
+
+    return Qnil;
+}
+
+/*
  * Gets the current rotate threshold size that is used by the default
  * logger.
  *
@@ -636,6 +679,10 @@ rb_grn_init_logger (VALUE mGrn)
                                rb_grn_logger_s_get_path, 0);
     rb_define_singleton_method(rb_cGrnLogger, "path=",
                                rb_grn_logger_s_set_path, 1);
+    rb_define_singleton_method(rb_cGrnLogger, "flags",
+                               rb_grn_logger_s_get_flags, 0);
+    rb_define_singleton_method(rb_cGrnLogger, "flags=",
+                               rb_grn_logger_s_set_flags, 1);
     rb_define_singleton_method(rb_cGrnLogger, "rotate_threshold_size",
                                rb_grn_logger_s_get_rotate_threshold_size, 0);
     rb_define_singleton_method(rb_cGrnLogger, "rotate_threshold_size=",

  Modified: test/test-logger.rb (+9 -0)
===================================================================
--- test/test-logger.rb    2016-12-12 19:40:33 +0900 (7fa0c07)
+++ test/test-logger.rb    2016-12-12 21:10:55 +0900 (e7b17cd)
@@ -1,4 +1,5 @@
 # Copyright (C) 2010  Kouhei Sutou <kou �� clear-code.com>
+# Copyright (C) 2016  Masafumi Yokoyama <yokoyama �� 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
@@ -43,6 +44,14 @@ class LoggerTest < Test::Unit::TestCase
     assert_equal(:debug, Groonga::Logger.max_level)
   end
 
+  def test_flags
+    default_flags = Groonga::Logger::Flags::TIME |
+                      Groonga::Logger::Flags::MESSAGE
+    assert_equal(default_flags, Groonga::Logger.flags)
+    Groonga::Logger.flags = Groonga::Logger::Flags::LOCATION
+    assert_equal(Groonga::Logger::Flags::LOCATION, Groonga::Logger.flags)
+  end
+
   sub_test_case ".log" do
     test "no options" do
       messages = []
-------------- next part --------------
HTML����������������������������...
다운로드 



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