[Groonga-commit] ranguba/rroonga at 0b3eb99 [master] Add Groonga::Logger.flags and Groonga::Logger.flags= (#141)

Back to archive index

Masafumi Yokoyama null+****@clear*****
Thu Jan 12 09:26:48 JST 2017


Masafumi Yokoyama	2017-01-12 09:26:48 +0900 (Thu, 12 Jan 2017)

  New Revision: 0b3eb99a95c3316016436dfeae5cfc297c9b84e3
  https://github.com/ranguba/rroonga/commit/0b3eb99a95c3316016436dfeae5cfc297c9b84e3

  Message:
    Add Groonga::Logger.flags and Groonga::Logger.flags= (#141)
    
    Patch by Masafumi Yokoyama. Thanks!!!

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

  Modified: ext/groonga/rb-grn-logger.c (+42 -0)
===================================================================
--- ext/groonga/rb-grn-logger.c    2017-01-11 18:36:37 +0900 (8ff4f0a)
+++ ext/groonga/rb-grn-logger.c    2017-01-12 09:26:48 +0900 (7b1483d)
@@ -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-2017  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,43 @@ 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 = INT2NUM(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)
+{
+    grn_default_logger_set_flags(NUM2INT(rb_flags));
+
+    return Qnil;
+}
+
+/*
  * Gets the current rotate threshold size that is used by the default
  * logger.
  *
@@ -636,6 +674,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    2017-01-11 18:36:37 +0900 (2a670bf)
+++ test/test-logger.rb    2017-01-12 09:26:48 +0900 (7438d7c)
@@ -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����������������������������...
Download 



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