rroonga 0.9.2-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +5 -0
- data/NEWS.ja.rdoc +114 -0
- data/NEWS.rdoc +116 -0
- data/README.ja.rdoc +65 -0
- data/README.rdoc +66 -0
- data/Rakefile +206 -0
- data/benchmark/common.rb +49 -0
- data/benchmark/read-write-many-small-items.rb +144 -0
- data/benchmark/write-many-small-items.rb +135 -0
- data/example/bookmark.rb +161 -0
- data/example/index-html.rb +89 -0
- data/example/search/config.ru +230 -0
- data/example/search/public/css/groonga.css +122 -0
- data/ext/.gitignore +2 -0
- data/ext/groonga/extconf.rb +93 -0
- data/ext/groonga/rb-grn-accessor.c +52 -0
- data/ext/groonga/rb-grn-array-cursor.c +36 -0
- data/ext/groonga/rb-grn-array.c +210 -0
- data/ext/groonga/rb-grn-column.c +573 -0
- data/ext/groonga/rb-grn-context.c +662 -0
- data/ext/groonga/rb-grn-database.c +472 -0
- data/ext/groonga/rb-grn-encoding-support.c +64 -0
- data/ext/groonga/rb-grn-encoding.c +257 -0
- data/ext/groonga/rb-grn-exception.c +1110 -0
- data/ext/groonga/rb-grn-expression-builder.c +75 -0
- data/ext/groonga/rb-grn-expression.c +731 -0
- data/ext/groonga/rb-grn-fix-size-column.c +166 -0
- data/ext/groonga/rb-grn-hash-cursor.c +38 -0
- data/ext/groonga/rb-grn-hash.c +294 -0
- data/ext/groonga/rb-grn-index-column.c +488 -0
- data/ext/groonga/rb-grn-logger.c +504 -0
- data/ext/groonga/rb-grn-object.c +1369 -0
- data/ext/groonga/rb-grn-operation.c +198 -0
- data/ext/groonga/rb-grn-patricia-trie-cursor.c +39 -0
- data/ext/groonga/rb-grn-patricia-trie.c +488 -0
- data/ext/groonga/rb-grn-procedure.c +52 -0
- data/ext/groonga/rb-grn-query.c +260 -0
- data/ext/groonga/rb-grn-record.c +40 -0
- data/ext/groonga/rb-grn-snippet.c +334 -0
- data/ext/groonga/rb-grn-table-cursor-key-support.c +69 -0
- data/ext/groonga/rb-grn-table-cursor.c +247 -0
- data/ext/groonga/rb-grn-table-key-support.c +714 -0
- data/ext/groonga/rb-grn-table.c +1977 -0
- data/ext/groonga/rb-grn-type.c +181 -0
- data/ext/groonga/rb-grn-utils.c +769 -0
- data/ext/groonga/rb-grn-variable-size-column.c +36 -0
- data/ext/groonga/rb-grn-variable.c +108 -0
- data/ext/groonga/rb-grn-view-accessor.c +53 -0
- data/ext/groonga/rb-grn-view-cursor.c +35 -0
- data/ext/groonga/rb-grn-view-record.c +41 -0
- data/ext/groonga/rb-grn-view.c +421 -0
- data/ext/groonga/rb-grn.h +698 -0
- data/ext/groonga/rb-groonga.c +107 -0
- data/extconf.rb +130 -0
- data/html/bar.svg +153 -0
- data/html/developer.html +117 -0
- data/html/developer.svg +469 -0
- data/html/download.svg +253 -0
- data/html/favicon.ico +0 -0
- data/html/favicon.xcf +0 -0
- data/html/footer.html.erb +28 -0
- data/html/head.html.erb +4 -0
- data/html/header.html.erb +17 -0
- data/html/index.html +147 -0
- data/html/install.svg +636 -0
- data/html/logo.xcf +0 -0
- data/html/ranguba.css +250 -0
- data/html/tutorial.svg +559 -0
- data/lib/1.8/groonga.so +0 -0
- data/lib/1.9/groonga.so +0 -0
- data/lib/groonga.rb +90 -0
- data/lib/groonga/context.rb +184 -0
- data/lib/groonga/expression-builder.rb +324 -0
- data/lib/groonga/patricia-trie.rb +85 -0
- data/lib/groonga/record.rb +311 -0
- data/lib/groonga/schema.rb +1191 -0
- data/lib/groonga/view-record.rb +56 -0
- data/license/GPL +340 -0
- data/license/LGPL +504 -0
- data/license/RUBY +59 -0
- data/misc/grnop2ruby.rb +49 -0
- data/pkg-config.rb +333 -0
- data/rroonga-build.rb +57 -0
- data/test-unit/Rakefile +40 -0
- data/test-unit/TODO +5 -0
- data/test-unit/bin/testrb +5 -0
- data/test-unit/html/classic.html +15 -0
- data/test-unit/html/index.html +25 -0
- data/test-unit/html/index.html.ja +27 -0
- data/test-unit/lib/test/unit.rb +323 -0
- data/test-unit/lib/test/unit/assertionfailederror.rb +25 -0
- data/test-unit/lib/test/unit/assertions.rb +1230 -0
- data/test-unit/lib/test/unit/attribute.rb +125 -0
- data/test-unit/lib/test/unit/autorunner.rb +360 -0
- data/test-unit/lib/test/unit/collector.rb +36 -0
- data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
- data/test-unit/lib/test/unit/collector/dir.rb +108 -0
- data/test-unit/lib/test/unit/collector/load.rb +144 -0
- data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
- data/test-unit/lib/test/unit/color-scheme.rb +102 -0
- data/test-unit/lib/test/unit/color.rb +96 -0
- data/test-unit/lib/test/unit/diff.rb +724 -0
- data/test-unit/lib/test/unit/error.rb +130 -0
- data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
- data/test-unit/lib/test/unit/failure.rb +136 -0
- data/test-unit/lib/test/unit/fixture.rb +176 -0
- data/test-unit/lib/test/unit/notification.rb +129 -0
- data/test-unit/lib/test/unit/omission.rb +191 -0
- data/test-unit/lib/test/unit/pending.rb +150 -0
- data/test-unit/lib/test/unit/priority.rb +180 -0
- data/test-unit/lib/test/unit/runner/console.rb +52 -0
- data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
- data/test-unit/lib/test/unit/runner/tap.rb +8 -0
- data/test-unit/lib/test/unit/testcase.rb +476 -0
- data/test-unit/lib/test/unit/testresult.rb +89 -0
- data/test-unit/lib/test/unit/testsuite.rb +110 -0
- data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
- data/test-unit/lib/test/unit/ui/console/testrunner.rb +466 -0
- data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +63 -0
- data/test-unit/lib/test/unit/ui/tap/testrunner.rb +92 -0
- data/test-unit/lib/test/unit/ui/testrunner.rb +28 -0
- data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
- data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
- data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
- data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
- data/test-unit/lib/test/unit/util/observable.rb +90 -0
- data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
- data/test-unit/lib/test/unit/version.rb +7 -0
- data/test-unit/sample/adder.rb +13 -0
- data/test-unit/sample/subtracter.rb +12 -0
- data/test-unit/sample/test_adder.rb +20 -0
- data/test-unit/sample/test_subtracter.rb +20 -0
- data/test-unit/sample/test_user.rb +23 -0
- data/test-unit/test/collector/test-descendant.rb +133 -0
- data/test-unit/test/collector/test-load.rb +442 -0
- data/test-unit/test/collector/test_dir.rb +406 -0
- data/test-unit/test/collector/test_objectspace.rb +100 -0
- data/test-unit/test/run-test.rb +15 -0
- data/test-unit/test/test-attribute.rb +86 -0
- data/test-unit/test/test-color-scheme.rb +67 -0
- data/test-unit/test/test-color.rb +47 -0
- data/test-unit/test/test-diff.rb +518 -0
- data/test-unit/test/test-emacs-runner.rb +60 -0
- data/test-unit/test/test-fixture.rb +287 -0
- data/test-unit/test/test-notification.rb +33 -0
- data/test-unit/test/test-omission.rb +81 -0
- data/test-unit/test/test-pending.rb +70 -0
- data/test-unit/test/test-priority.rb +119 -0
- data/test-unit/test/test-testcase.rb +544 -0
- data/test-unit/test/test_assertions.rb +1151 -0
- data/test-unit/test/test_error.rb +26 -0
- data/test-unit/test/test_failure.rb +33 -0
- data/test-unit/test/test_testresult.rb +113 -0
- data/test-unit/test/test_testsuite.rb +129 -0
- data/test-unit/test/testunit-test-util.rb +14 -0
- data/test-unit/test/ui/test_testrunmediator.rb +20 -0
- data/test-unit/test/util/test-method-owner-finder.rb +38 -0
- data/test-unit/test/util/test_backtracefilter.rb +41 -0
- data/test-unit/test/util/test_observable.rb +102 -0
- data/test-unit/test/util/test_procwrapper.rb +36 -0
- data/test/.gitignore +1 -0
- data/test/groonga-test-utils.rb +134 -0
- data/test/run-test.rb +58 -0
- data/test/test-array.rb +90 -0
- data/test/test-column.rb +316 -0
- data/test/test-context-select.rb +93 -0
- data/test/test-context.rb +73 -0
- data/test/test-database.rb +113 -0
- data/test/test-encoding.rb +33 -0
- data/test/test-exception.rb +93 -0
- data/test/test-expression-builder.rb +217 -0
- data/test/test-expression.rb +134 -0
- data/test/test-fix-size-column.rb +65 -0
- data/test/test-gqtp.rb +72 -0
- data/test/test-hash.rb +305 -0
- data/test/test-index-column.rb +81 -0
- data/test/test-logger.rb +37 -0
- data/test/test-patricia-trie.rb +205 -0
- data/test/test-procedure.rb +37 -0
- data/test/test-query.rb +22 -0
- data/test/test-record.rb +243 -0
- data/test/test-remote.rb +54 -0
- data/test/test-schema-view.rb +90 -0
- data/test/test-schema.rb +459 -0
- data/test/test-snippet.rb +130 -0
- data/test/test-table-cursor.rb +153 -0
- data/test/test-table-offset-and-limit.rb +102 -0
- data/test/test-table-select-normalize.rb +53 -0
- data/test/test-table-select.rb +150 -0
- data/test/test-table.rb +594 -0
- data/test/test-type.rb +71 -0
- data/test/test-variable-size-column.rb +98 -0
- data/test/test-variable.rb +28 -0
- data/test/test-vector-column.rb +76 -0
- data/test/test-version.rb +31 -0
- data/test/test-view.rb +72 -0
- data/text/TUTORIAL.ja.rdoc +392 -0
- data/text/expression.rdoc +284 -0
- metadata +276 -0
@@ -0,0 +1,504 @@
|
|
1
|
+
/* -*- c-file-style: "ruby" -*- */
|
2
|
+
/*
|
3
|
+
Copyright (C) 2009-2010 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
|
5
|
+
This library is free software; you can redistribute it and/or
|
6
|
+
modify it under the terms of the GNU Lesser General Public
|
7
|
+
License version 2.1 as published by the Free Software Foundation.
|
8
|
+
|
9
|
+
This library is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
Lesser General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU Lesser General Public
|
15
|
+
License along with this library; if not, write to the Free Software
|
16
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include "rb-grn.h"
|
20
|
+
|
21
|
+
/* FIXME */
|
22
|
+
void grn_log_reopen(grn_ctx *ctx);
|
23
|
+
extern const char *grn_log_path;
|
24
|
+
extern const char *grn_qlog_path;
|
25
|
+
|
26
|
+
|
27
|
+
/*
|
28
|
+
* Document-class: Groonga::Logger
|
29
|
+
*
|
30
|
+
* groongaから出力されるログを記録するためのクラス。
|
31
|
+
*
|
32
|
+
*/
|
33
|
+
|
34
|
+
#define RVAL2GRNWRAPPER(object) (rb_grn_logger_info_wrapper_from_ruby_object(object))
|
35
|
+
#define RVAL2GRNLOGLEVEL(object) (rb_grn_log_level_from_ruby_object(object))
|
36
|
+
#define GRNLOGLEVEL2RVAL(level) (rb_grn_log_level_to_ruby_object(level))
|
37
|
+
|
38
|
+
VALUE cGrnLogger;
|
39
|
+
|
40
|
+
typedef struct _rb_grn_logger_info_wrapper
|
41
|
+
{
|
42
|
+
grn_logger_info *logger;
|
43
|
+
VALUE handler;
|
44
|
+
} rb_grn_logger_info_wrapper;
|
45
|
+
|
46
|
+
static rb_grn_logger_info_wrapper *
|
47
|
+
rb_grn_logger_info_wrapper_from_ruby_object (VALUE object)
|
48
|
+
{
|
49
|
+
rb_grn_logger_info_wrapper *wrapper;
|
50
|
+
|
51
|
+
if (NIL_P(object))
|
52
|
+
return NULL;
|
53
|
+
|
54
|
+
if (!RVAL2CBOOL(rb_obj_is_kind_of(object, cGrnLogger))) {
|
55
|
+
rb_raise(rb_eTypeError, "not a groonga logger");
|
56
|
+
}
|
57
|
+
|
58
|
+
Data_Get_Struct(object, rb_grn_logger_info_wrapper, wrapper);
|
59
|
+
if (!wrapper)
|
60
|
+
rb_raise(rb_eTypeError, "groonga logger is NULL");
|
61
|
+
|
62
|
+
return wrapper;
|
63
|
+
}
|
64
|
+
|
65
|
+
grn_logger_info *
|
66
|
+
rb_grn_logger_from_ruby_object (VALUE object)
|
67
|
+
{
|
68
|
+
rb_grn_logger_info_wrapper *wrapper;
|
69
|
+
|
70
|
+
wrapper = RVAL2GRNWRAPPER(object);
|
71
|
+
if (!wrapper)
|
72
|
+
return NULL;
|
73
|
+
|
74
|
+
return wrapper->logger;
|
75
|
+
}
|
76
|
+
|
77
|
+
static void
|
78
|
+
rb_grn_logger_free (void *object)
|
79
|
+
{
|
80
|
+
rb_grn_logger_info_wrapper *wrapper = object;
|
81
|
+
|
82
|
+
xfree(wrapper->logger);
|
83
|
+
xfree(wrapper);
|
84
|
+
}
|
85
|
+
|
86
|
+
static VALUE
|
87
|
+
rb_grn_logger_alloc (VALUE klass)
|
88
|
+
{
|
89
|
+
return Data_Wrap_Struct(klass, NULL, rb_grn_logger_free, NULL);
|
90
|
+
}
|
91
|
+
|
92
|
+
static grn_log_level
|
93
|
+
rb_grn_log_level_from_ruby_object (VALUE rb_level)
|
94
|
+
{
|
95
|
+
grn_log_level level = GRN_LOG_NONE;
|
96
|
+
|
97
|
+
if (NIL_P(rb_level)) {
|
98
|
+
level = GRN_LOG_DEFAULT_LEVEL;
|
99
|
+
} else if (rb_grn_equal_option(rb_level, "none")) {
|
100
|
+
level = GRN_LOG_NONE;
|
101
|
+
} else if (rb_grn_equal_option(rb_level, "emergency")) {
|
102
|
+
level = GRN_LOG_EMERG;
|
103
|
+
} else if (rb_grn_equal_option(rb_level, "alert")) {
|
104
|
+
level = GRN_LOG_ALERT;
|
105
|
+
} else if (rb_grn_equal_option(rb_level, "critical")) {
|
106
|
+
level = GRN_LOG_CRIT;
|
107
|
+
} else if (rb_grn_equal_option(rb_level, "error")) {
|
108
|
+
level = GRN_LOG_ERROR;
|
109
|
+
} else if (rb_grn_equal_option(rb_level, "warning")) {
|
110
|
+
level = GRN_LOG_WARNING;
|
111
|
+
} else if (rb_grn_equal_option(rb_level, "notice")) {
|
112
|
+
level = GRN_LOG_NOTICE;
|
113
|
+
} else if (rb_grn_equal_option(rb_level, "info")) {
|
114
|
+
level = GRN_LOG_INFO;
|
115
|
+
} else if (rb_grn_equal_option(rb_level, "debug")) {
|
116
|
+
level = GRN_LOG_DEBUG;
|
117
|
+
} else if (rb_grn_equal_option(rb_level, "dump")) {
|
118
|
+
level = GRN_LOG_DUMP;
|
119
|
+
} else {
|
120
|
+
rb_raise(rb_eArgError,
|
121
|
+
"log level should be one of "
|
122
|
+
"[nil, :none, :emergency, :alert, :critical, :error, "
|
123
|
+
":warning, :notice, :info, :debug, :dump]: %s",
|
124
|
+
rb_grn_inspect(rb_level));
|
125
|
+
}
|
126
|
+
|
127
|
+
return level;
|
128
|
+
}
|
129
|
+
|
130
|
+
static VALUE
|
131
|
+
rb_grn_log_level_to_ruby_object (grn_log_level level)
|
132
|
+
{
|
133
|
+
VALUE rb_level = Qnil;
|
134
|
+
|
135
|
+
switch (level) {
|
136
|
+
case GRN_LOG_NONE:
|
137
|
+
rb_level = RB_GRN_INTERN("none");
|
138
|
+
break;
|
139
|
+
case GRN_LOG_EMERG:
|
140
|
+
rb_level = RB_GRN_INTERN("emergency");
|
141
|
+
break;
|
142
|
+
case GRN_LOG_ALERT:
|
143
|
+
rb_level = RB_GRN_INTERN("alert");
|
144
|
+
break;
|
145
|
+
case GRN_LOG_CRIT:
|
146
|
+
rb_level = RB_GRN_INTERN("critical");
|
147
|
+
break;
|
148
|
+
case GRN_LOG_ERROR:
|
149
|
+
rb_level = RB_GRN_INTERN("error");
|
150
|
+
break;
|
151
|
+
case GRN_LOG_WARNING:
|
152
|
+
rb_level = RB_GRN_INTERN("warning");
|
153
|
+
break;
|
154
|
+
case GRN_LOG_NOTICE:
|
155
|
+
rb_level = RB_GRN_INTERN("notice");
|
156
|
+
break;
|
157
|
+
case GRN_LOG_INFO:
|
158
|
+
rb_level = RB_GRN_INTERN("info");
|
159
|
+
break;
|
160
|
+
case GRN_LOG_DEBUG:
|
161
|
+
rb_level = RB_GRN_INTERN("debug");
|
162
|
+
break;
|
163
|
+
case GRN_LOG_DUMP:
|
164
|
+
rb_level = RB_GRN_INTERN("dump");
|
165
|
+
break;
|
166
|
+
default:
|
167
|
+
rb_level = INT2NUM(level);
|
168
|
+
break;
|
169
|
+
}
|
170
|
+
|
171
|
+
return rb_level;
|
172
|
+
}
|
173
|
+
|
174
|
+
static void
|
175
|
+
rb_grn_log (int level, const char *time, const char *title,
|
176
|
+
const char *message, const char *location, void *func_arg)
|
177
|
+
{
|
178
|
+
rb_grn_logger_info_wrapper *wrapper = func_arg;
|
179
|
+
|
180
|
+
rb_funcall(wrapper->handler, rb_intern("call"), 5,
|
181
|
+
GRNLOGLEVEL2RVAL(level),
|
182
|
+
rb_str_new2(time),
|
183
|
+
rb_str_new2(title),
|
184
|
+
rb_str_new2(message),
|
185
|
+
rb_str_new2(location));
|
186
|
+
}
|
187
|
+
|
188
|
+
static void
|
189
|
+
rb_grn_logger_set_handler (VALUE self, VALUE rb_handler)
|
190
|
+
{
|
191
|
+
rb_grn_logger_info_wrapper *wrapper;
|
192
|
+
grn_logger_info *logger;
|
193
|
+
|
194
|
+
wrapper = RVAL2GRNWRAPPER(self);
|
195
|
+
wrapper->handler = rb_handler;
|
196
|
+
rb_iv_set(self, "@handler", rb_handler);
|
197
|
+
|
198
|
+
logger = wrapper->logger;
|
199
|
+
if (NIL_P(rb_handler)) {
|
200
|
+
logger->func = NULL;
|
201
|
+
logger->func_arg = NULL;
|
202
|
+
} else {
|
203
|
+
logger->func = rb_grn_log;
|
204
|
+
logger->func_arg = wrapper;
|
205
|
+
}
|
206
|
+
}
|
207
|
+
|
208
|
+
static VALUE
|
209
|
+
rb_grn_logger_initialize (int argc, VALUE *argv, VALUE self)
|
210
|
+
{
|
211
|
+
rb_grn_logger_info_wrapper *wrapper;
|
212
|
+
grn_logger_info *logger;
|
213
|
+
grn_log_level level;
|
214
|
+
int flags = 0;
|
215
|
+
VALUE options, rb_level, rb_time, rb_title, rb_message, rb_location;
|
216
|
+
VALUE rb_handler;
|
217
|
+
|
218
|
+
rb_scan_args(argc, argv, "01&", &options, &rb_handler);
|
219
|
+
|
220
|
+
rb_grn_scan_options(options,
|
221
|
+
"level", &rb_level,
|
222
|
+
"time", &rb_time,
|
223
|
+
"title", &rb_title,
|
224
|
+
"message", &rb_message,
|
225
|
+
"location", &rb_location,
|
226
|
+
NULL);
|
227
|
+
|
228
|
+
level = RVAL2GRNLOGLEVEL(rb_level);
|
229
|
+
|
230
|
+
if (NIL_P(rb_time) || RVAL2CBOOL(rb_time))
|
231
|
+
flags |= GRN_LOG_TIME;
|
232
|
+
if (NIL_P(rb_title) || RVAL2CBOOL(rb_title))
|
233
|
+
flags |= GRN_LOG_TITLE;
|
234
|
+
if (NIL_P(rb_message) || RVAL2CBOOL(rb_message))
|
235
|
+
flags |= GRN_LOG_MESSAGE;
|
236
|
+
if (NIL_P(rb_location) || RVAL2CBOOL(rb_location))
|
237
|
+
flags |= GRN_LOG_LOCATION;
|
238
|
+
|
239
|
+
wrapper = ALLOC(rb_grn_logger_info_wrapper);
|
240
|
+
logger = ALLOC(grn_logger_info);
|
241
|
+
wrapper->logger = logger;
|
242
|
+
DATA_PTR(self) = wrapper;
|
243
|
+
|
244
|
+
logger->max_level = level;
|
245
|
+
logger->flags = flags;
|
246
|
+
rb_grn_logger_set_handler(self, rb_handler);
|
247
|
+
|
248
|
+
return Qnil;
|
249
|
+
}
|
250
|
+
|
251
|
+
/*
|
252
|
+
* call-seq:
|
253
|
+
* Groonga::Logger.register(options={})
|
254
|
+
{|level, time, title, message, location| ...}
|
255
|
+
*
|
256
|
+
* groongaがログを出力する度に呼び出されるブロックを登録す
|
257
|
+
* る。
|
258
|
+
*
|
259
|
+
* ブロックに渡されてくる引数は_level_, _time_, _title_,
|
260
|
+
* _message_, _location_の5つで、_level_はSymbol、それ以外は
|
261
|
+
* 全て文字列で渡される。その4つについては_options_で+false+
|
262
|
+
* を指定することでブロックに渡さないようにすることができ、
|
263
|
+
* その場合は空文字列が実際には渡される。
|
264
|
+
*
|
265
|
+
* _options_に指定可能な値は以下の通り。
|
266
|
+
*
|
267
|
+
* [+:level+]
|
268
|
+
* ログのレベルを+:none+, +:emergency+, +:alert+,
|
269
|
+
* +:critical+, +:error+, +:warning+, +:notice+, +:info+,
|
270
|
+
* +:debug+, +:dump+のいずれかで指定する。それより重要度が
|
271
|
+
* 低いログはブロックに渡されなくなる。デフォルトでは
|
272
|
+
* +:notice+。
|
273
|
+
*
|
274
|
+
* [+:time+]
|
275
|
+
* ログが出力された時間をブロックに渡したいなら+true+を指
|
276
|
+
* 定する。デフォルトでは渡す。
|
277
|
+
*
|
278
|
+
* [+:title+]
|
279
|
+
* ログのタイトルをブロックに渡したいなら+true+を指定す
|
280
|
+
* る。デフォルトでは渡す。(FIXME: groongaで実装されてい
|
281
|
+
* ない?)
|
282
|
+
*
|
283
|
+
* [+:message+]
|
284
|
+
* ログのメッセージをブロックに渡したいなら+true+を指定す
|
285
|
+
* る。デフォルトでは渡す。
|
286
|
+
*
|
287
|
+
* [+:location+]
|
288
|
+
* ログの発生元のプロセスIDとgroongaのソースコードのファイ
|
289
|
+
* ル名、行番号、関数名をブロックに渡したいなら+true+を指
|
290
|
+
* 定する。デフォルトでは渡す。
|
291
|
+
*/
|
292
|
+
static VALUE
|
293
|
+
rb_grn_logger_s_register (int argc, VALUE *argv, VALUE klass)
|
294
|
+
{
|
295
|
+
VALUE logger, rb_context = Qnil;
|
296
|
+
grn_ctx *context;
|
297
|
+
|
298
|
+
logger = rb_funcall2(klass, rb_intern("new"), argc, argv);
|
299
|
+
rb_grn_logger_set_handler(logger, rb_block_proc());
|
300
|
+
context = rb_grn_context_ensure(&rb_context);
|
301
|
+
grn_logger_info_set(context, RVAL2GRNLOGGER(logger));
|
302
|
+
rb_grn_context_check(context, logger);
|
303
|
+
rb_cv_set(klass, "@@current_logger", logger);
|
304
|
+
|
305
|
+
return Qnil;
|
306
|
+
}
|
307
|
+
|
308
|
+
static void
|
309
|
+
rb_grn_logger_reset_with_error_check (VALUE klass, grn_ctx *context)
|
310
|
+
{
|
311
|
+
VALUE current_logger;
|
312
|
+
|
313
|
+
current_logger = rb_cv_get(klass, "@@current_logger");
|
314
|
+
if (NIL_P(current_logger))
|
315
|
+
return;
|
316
|
+
|
317
|
+
rb_cv_set(klass, "@@current_logger", Qnil);
|
318
|
+
if (context) {
|
319
|
+
grn_logger_info_set(context, NULL);
|
320
|
+
rb_grn_context_check(context, current_logger);
|
321
|
+
} else {
|
322
|
+
grn_logger_info_set(NULL, NULL);
|
323
|
+
}
|
324
|
+
}
|
325
|
+
|
326
|
+
static void
|
327
|
+
rb_grn_logger_reset (VALUE klass)
|
328
|
+
{
|
329
|
+
rb_grn_logger_reset_with_error_check(klass, NULL);
|
330
|
+
}
|
331
|
+
|
332
|
+
static VALUE
|
333
|
+
rb_grn_logger_s_reopen_with_related_object (VALUE klass, VALUE related_object)
|
334
|
+
{
|
335
|
+
#ifdef WIN32
|
336
|
+
rb_raise(rb_eNotImpError, "grn_log_reopen() isn't available on Windows.");
|
337
|
+
#else
|
338
|
+
VALUE rb_context = Qnil;
|
339
|
+
grn_ctx *context;
|
340
|
+
|
341
|
+
context = rb_grn_context_ensure(&rb_context);
|
342
|
+
rb_grn_logger_reset_with_error_check(klass, context);
|
343
|
+
grn_log_reopen(context);
|
344
|
+
rb_grn_context_check(context, related_object);
|
345
|
+
#endif
|
346
|
+
|
347
|
+
return Qnil;
|
348
|
+
}
|
349
|
+
|
350
|
+
/*
|
351
|
+
* call-seq:
|
352
|
+
* Groonga::Logger.reopen
|
353
|
+
*
|
354
|
+
* groongaのデフォルトロガーがログを出力するファイルを再オー
|
355
|
+
* プンする。ログファイルのバックアップ時などに使用する。
|
356
|
+
*
|
357
|
+
* Groonga::Logger.registerで独自のロガーを設定している場合
|
358
|
+
* は例外が発生する。
|
359
|
+
*/
|
360
|
+
static VALUE
|
361
|
+
rb_grn_logger_s_reopen (VALUE klass)
|
362
|
+
{
|
363
|
+
return rb_grn_logger_s_reopen_with_related_object(klass, klass);
|
364
|
+
}
|
365
|
+
|
366
|
+
#ifndef WIN32
|
367
|
+
static VALUE
|
368
|
+
rb_grn_logger_s_set_path (VALUE klass, VALUE rb_path,
|
369
|
+
const char **path, const char *class_variable_name)
|
370
|
+
{
|
371
|
+
rb_grn_boolean need_reopen = RB_GRN_FALSE;
|
372
|
+
|
373
|
+
if (NIL_P(rb_path)) {
|
374
|
+
need_reopen = *path != NULL;
|
375
|
+
*path = NULL;
|
376
|
+
} else {
|
377
|
+
const char *current_path = *path;
|
378
|
+
*path = RSTRING_PTR(rb_path);
|
379
|
+
if (!current_path || strcmp(*path, current_path) != 0) {
|
380
|
+
need_reopen = RB_GRN_TRUE;
|
381
|
+
}
|
382
|
+
}
|
383
|
+
rb_cv_set(klass, class_variable_name, rb_path);
|
384
|
+
|
385
|
+
if (need_reopen) {
|
386
|
+
rb_grn_logger_s_reopen_with_related_object(klass, rb_path);
|
387
|
+
}
|
388
|
+
|
389
|
+
return Qnil;
|
390
|
+
}
|
391
|
+
#endif
|
392
|
+
|
393
|
+
/*
|
394
|
+
* call-seq:
|
395
|
+
* Groonga::Logger.log_path # => log_path
|
396
|
+
*
|
397
|
+
* groongaのデフォルトロガーがログを出力するファイルの
|
398
|
+
* パスを返す。
|
399
|
+
*/
|
400
|
+
static VALUE
|
401
|
+
rb_grn_logger_s_get_log_path (VALUE klass)
|
402
|
+
{
|
403
|
+
#ifdef WIN32
|
404
|
+
rb_raise(rb_eNotImpError, "grn_log_path isn't available on Windows.");
|
405
|
+
return Qnil;
|
406
|
+
#else
|
407
|
+
if (grn_log_path) {
|
408
|
+
return rb_str_new2(grn_log_path);
|
409
|
+
} else {
|
410
|
+
return Qnil;
|
411
|
+
}
|
412
|
+
#endif
|
413
|
+
}
|
414
|
+
|
415
|
+
/*
|
416
|
+
* call-seq:
|
417
|
+
* Groonga::Logger.log_path = log_path
|
418
|
+
*
|
419
|
+
* groongaのデフォルトロガーがログを出力するファイルのパスを
|
420
|
+
* 指定する。
|
421
|
+
*
|
422
|
+
* Groonga::Logger.registerで独自のロガーを設定している場合、
|
423
|
+
* 設定している独自ロガーは無効になる。
|
424
|
+
*/
|
425
|
+
static VALUE
|
426
|
+
rb_grn_logger_s_set_log_path (VALUE klass, VALUE path)
|
427
|
+
{
|
428
|
+
#ifdef WIN32
|
429
|
+
rb_raise(rb_eNotImpError, "grn_qlog_path isn't available on Windows.");
|
430
|
+
return Qnil;
|
431
|
+
#else
|
432
|
+
return rb_grn_logger_s_set_path(klass, path, &grn_log_path, "@@log_path");
|
433
|
+
#endif
|
434
|
+
}
|
435
|
+
|
436
|
+
/*
|
437
|
+
* call-seq:
|
438
|
+
* Groonga::Logger.query_log_path # => query_log_path
|
439
|
+
*
|
440
|
+
* groongaのデフォルトロガーがクエリログを出力するファイルの
|
441
|
+
* パスを返す。
|
442
|
+
*/
|
443
|
+
static VALUE
|
444
|
+
rb_grn_logger_s_get_query_log_path (VALUE klass)
|
445
|
+
{
|
446
|
+
#ifdef WIN32
|
447
|
+
rb_raise(rb_eNotImpError, "grn_qlog_path isn't available on Windows.");
|
448
|
+
return Qnil;
|
449
|
+
#else
|
450
|
+
if (grn_qlog_path) {
|
451
|
+
return rb_str_new2(grn_qlog_path);
|
452
|
+
} else {
|
453
|
+
return Qnil;
|
454
|
+
}
|
455
|
+
#endif
|
456
|
+
}
|
457
|
+
|
458
|
+
/*
|
459
|
+
* call-seq:
|
460
|
+
* Groonga::Logger.query_log_path = query_log_path
|
461
|
+
*
|
462
|
+
* groongaのデフォルトロガーがクエリログを出力するファイルの
|
463
|
+
* パスを指定する。
|
464
|
+
*
|
465
|
+
* Groonga::Logger.registerで独自のロガーを設定している場合、
|
466
|
+
* 設定している独自ロガーは無効になる。
|
467
|
+
*/
|
468
|
+
static VALUE
|
469
|
+
rb_grn_logger_s_set_query_log_path (VALUE klass, VALUE path)
|
470
|
+
{
|
471
|
+
#ifdef WIN32
|
472
|
+
rb_raise(rb_eNotImpError, "grn_qlog_path isn't available on Windows.");
|
473
|
+
return Qnil;
|
474
|
+
#else
|
475
|
+
return rb_grn_logger_s_set_path(klass, path, &grn_qlog_path,
|
476
|
+
"@@query_log_path");
|
477
|
+
#endif
|
478
|
+
}
|
479
|
+
|
480
|
+
void
|
481
|
+
rb_grn_init_logger (VALUE mGrn)
|
482
|
+
{
|
483
|
+
cGrnLogger = rb_define_class_under(mGrn, "Logger", rb_cObject);
|
484
|
+
rb_define_alloc_func(cGrnLogger, rb_grn_logger_alloc);
|
485
|
+
|
486
|
+
rb_cv_set(cGrnLogger, "@@current_logger", Qnil);
|
487
|
+
rb_cv_set(cGrnLogger, "@@log_path", Qnil);
|
488
|
+
rb_cv_set(cGrnLogger, "@@query_log_path", Qnil);
|
489
|
+
rb_define_singleton_method(cGrnLogger, "register",
|
490
|
+
rb_grn_logger_s_register, -1);
|
491
|
+
rb_define_singleton_method(cGrnLogger, "reopen",
|
492
|
+
rb_grn_logger_s_reopen, 0);
|
493
|
+
rb_define_singleton_method(cGrnLogger, "log_path",
|
494
|
+
rb_grn_logger_s_get_log_path, 0);
|
495
|
+
rb_define_singleton_method(cGrnLogger, "log_path=",
|
496
|
+
rb_grn_logger_s_set_log_path, 1);
|
497
|
+
rb_define_singleton_method(cGrnLogger, "query_log_path",
|
498
|
+
rb_grn_logger_s_get_query_log_path, 0);
|
499
|
+
rb_define_singleton_method(cGrnLogger, "query_log_path=",
|
500
|
+
rb_grn_logger_s_set_query_log_path, 1);
|
501
|
+
rb_set_end_proc(rb_grn_logger_reset, cGrnLogger);
|
502
|
+
|
503
|
+
rb_define_method(cGrnLogger, "initialize", rb_grn_logger_initialize, -1);
|
504
|
+
}
|