[Groonga-commit] ranguba/rroonga at f9d08fd [master] Add Groonga::WindowsEventLogger.register

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Sep 8 17:50:02 JST 2015


Kouhei Sutou	2015-09-08 17:50:02 +0900 (Tue, 08 Sep 2015)

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

  Message:
    Add Groonga::WindowsEventLogger.register

  Added files:
    ext/groonga/rb-grn-windows-event-logger.c
    test/test-windows-event-logger.rb
  Modified files:
    ext/groonga/rb-grn.h
    ext/groonga/rb-groonga.c
    test/groonga-test-utils.rb

  Added: ext/groonga/rb-grn-windows-event-logger.c (+79 -0) 100644
===================================================================
--- /dev/null
+++ ext/groonga/rb-grn-windows-event-logger.c    2015-09-08 17:50:02 +0900 (f5a505e)
@@ -0,0 +1,79 @@
+/* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+  Copyright (C) 2015  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
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include "rb-grn.h"
+
+/*
+ * Document-class: Groonga::WindowsEventLogger
+ *
+ * It's a module for using Windows Event Log as log output.
+ */
+
+/*
+ * @overload register(event_source_name, options={})
+ *
+ *   Registers Windows Event Log based logger that uses
+ *   `event_source_name` as event source name.
+ *
+ *   @param event_source_name [String] The event source name.
+ *   @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_windows_event_logger_s_register (int argc,
+                                        VALUE *argv,
+                                        VALUE klass)
+{
+    VALUE rb_event_source_name;
+    VALUE rb_options;
+    VALUE rb_context;
+    const char *event_source_name;
+    grn_ctx *context;
+    grn_rc rc;
+
+    rb_scan_args(argc, argv, "11", &rb_event_source_name, &rb_options);
+    rb_event_source_name = rb_grn_convert_to_string(rb_event_source_name);
+    event_source_name = StringValueCStr(rb_event_source_name);
+
+    rb_grn_scan_options(rb_options,
+                        "context", &rb_context,
+                        NULL);
+    context = rb_grn_context_ensure(&rb_context);
+
+    rc = grn_windows_event_logger_set(context, event_source_name);
+    rb_grn_context_check(context, rb_event_source_name);
+    rb_grn_rc_check(rc, rb_event_source_name);
+
+    return Qnil;
+}
+
+void
+rb_grn_init_windows_event_logger (VALUE mGrn)
+{
+    VALUE mGrnWindowsEventLogger;
+
+    mGrnWindowsEventLogger = rb_define_module_under(mGrn, "WindowsEventLogger");
+
+    rb_define_singleton_method(mGrnWindowsEventLogger, "register",
+                               rb_grn_windows_event_logger_s_register, -1);
+}

  Modified: ext/groonga/rb-grn.h (+1 -0)
===================================================================
--- ext/groonga/rb-grn.h    2015-09-08 17:31:39 +0900 (12ee852)
+++ ext/groonga/rb-grn.h    2015-09-08 17:50:02 +0900 (4264d2d)
@@ -349,6 +349,7 @@ void           rb_grn_init_expression               (VALUE mGrn);
 void           rb_grn_init_expression_builder       (VALUE mGrn);
 void           rb_grn_init_logger                   (VALUE mGrn);
 void           rb_grn_init_query_logger             (VALUE mGrn);
+void           rb_grn_init_windows_event_logger     (VALUE mGrn);
 void           rb_grn_init_snippet                  (VALUE mGrn);
 void           rb_grn_init_plugin                   (VALUE mGrn);
 void           rb_grn_init_normalizer               (VALUE mGrn);

  Modified: ext/groonga/rb-groonga.c (+2 -1)
===================================================================
--- ext/groonga/rb-groonga.c    2015-09-08 17:31:39 +0900 (1a36b7d)
+++ ext/groonga/rb-groonga.c    2015-09-08 17:50:02 +0900 (e9177fc)
@@ -1,6 +1,6 @@
 /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /*
-  Copyright (C) 2009-2014  Kouhei Sutou <kou �� clear-code.com>
+  Copyright (C) 2009-2015  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
@@ -187,6 +187,7 @@ Init_groonga (void)
     rb_grn_init_expression_builder(mGrn);
     rb_grn_init_logger(mGrn);
     rb_grn_init_query_logger(mGrn);
+    rb_grn_init_windows_event_logger(mGrn);
     rb_grn_init_snippet(mGrn);
     rb_grn_init_plugin(mGrn);
     rb_grn_init_normalizer(mGrn);

  Modified: test/groonga-test-utils.rb (+5 -1)
===================================================================
--- test/groonga-test-utils.rb    2015-09-08 17:31:39 +0900 (733cde9)
+++ test/groonga-test-utils.rb    2015-09-08 17:50:02 +0900 (067295c)
@@ -1,5 +1,5 @@
 # Copyright (C) 2015  Masafumi Yokoyama <yokoyama �� clear-code.com>
-# Copyright (C) 2009-2014  Kouhei Sutou <kou �� clear-code.com>
+# Copyright (C) 2009-2015  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
@@ -174,6 +174,10 @@ module GroongaTestUtils
     omit("This test is only for Linux system.") unless linux?
   end
 
+  def windows?
+    /cygwin|mingw|mswin/ === RUBY_PLATFORM
+  end
+
   def support_self_recursive_equal?
     self_recursive_hash1 = {}
     self_recursive_hash1["next"] = self_recursive_hash1

  Added: test/test-windows-event-logger.rb (+28 -0) 100644
===================================================================
--- /dev/null
+++ test/test-windows-event-logger.rb    2015-09-08 17:50:02 +0900 (e528d69)
@@ -0,0 +1,28 @@
+# Copyright (C) 2015  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
+# License version 2.1 as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+class WindowsEventLoggerTest < Test::Unit::TestCase
+  include GroongaTestUtils
+
+  test "#register" do
+    if windows?
+      Groonga::WindowsEventLogger.register("Rroonga")
+    else
+      assert_raise(Groonga::FunctionNotImplemented) do
+        Groonga::WindowsEventLogger.register("Rroonga")
+      end
+    end
+  end
+end
-------------- next part --------------
HTML����������������������������...
Download 



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