Kouhei Sutou
null+****@clear*****
Thu Aug 7 12:04:03 JST 2014
Kouhei Sutou 2014-08-07 12:04:03 +0900 (Thu, 07 Aug 2014) New Revision: 74585fcec23fa878444b60bd99586781bb6b5f71 https://github.com/groonga/groonga/commit/74585fcec23fa878444b60bd99586781bb6b5f71 Message: mrb: bind minimum logger functions Added files: lib/mrb/mrb_logger.c lib/mrb/mrb_logger.h Modified files: lib/ctx_impl_mrb.c lib/mrb/sources.am Modified: lib/ctx_impl_mrb.c (+2 -0) =================================================================== --- lib/ctx_impl_mrb.c 2014-08-07 12:00:01 +0900 (f2f53f3) +++ lib/ctx_impl_mrb.c 2014-08-07 12:04:03 +0900 (e72ad90) @@ -23,6 +23,7 @@ #include "mrb/mrb_id.h" #include "mrb/mrb_operator.h" #include "mrb/mrb_ctx.h" +#include "mrb/mrb_logger.h" #include "mrb/mrb_bulk.h" #include "mrb/mrb_obj.h" #include "mrb/mrb_column.h" @@ -45,6 +46,7 @@ grn_ctx_impl_mrb_init_bindings(grn_ctx *ctx) grn_mrb_id_init(ctx); grn_mrb_operator_init(ctx); grn_mrb_ctx_init(ctx); + grn_mrb_logger_init(ctx); grn_mrb_bulk_init(ctx); grn_mrb_obj_init(ctx); grn_mrb_column_init(ctx); Added: lib/mrb/mrb_logger.c (+73 -0) 100644 =================================================================== --- /dev/null +++ lib/mrb/mrb_logger.c 2014-08-07 12:04:03 +0900 (f42d2a7) @@ -0,0 +1,73 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2014 Brazil + + 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 "../ctx_impl.h" + +#ifdef GRN_WITH_MRUBY +#include <mruby.h> +#include <mruby/class.h> +#include <mruby/data.h> +#include <mruby/variable.h> +#include <mruby/string.h> + +#include "../mrb.h" +#include "mrb_logger.h" + +static mrb_value +logger_need_log_p(mrb_state *mrb, mrb_value self) +{ + grn_ctx *ctx = (grn_ctx *)mrb->ud; + mrb_int level; + + mrb_get_args(mrb, "i", &level); + + return mrb_bool_value(grn_logger_pass(ctx, level)); +} + +static mrb_value +logger_log(mrb_state *mrb, mrb_value self) +{ + grn_ctx *ctx = (grn_ctx *)mrb->ud; + mrb_int level; + char *file; + mrb_int line; + char *method; + char *message; + mrb_int message_size; + + mrb_get_args(mrb, "izizs", + &level, &file, &line, &method, &message, &message_size); + grn_logger_put(ctx, level, file, line, method, "%.*s", message_size, message); + + return self; +} + +void +grn_mrb_logger_init(grn_ctx *ctx) +{ + grn_mrb_data *data = &(ctx->impl->mrb); + mrb_state *mrb = data->state; + struct RClass *module = data->module; + struct RClass *klass; + + klass = mrb_define_class_under(mrb, module, "Logger", mrb->object_class); + + mrb_define_method(mrb, klass, "need_log?", logger_need_log_p, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, klass, "log", logger_log, MRB_ARGS_REQ(5)); +} +#endif Added: lib/mrb/mrb_logger.h (+34 -0) 100644 =================================================================== --- /dev/null +++ lib/mrb/mrb_logger.h 2014-08-07 12:04:03 +0900 (5bfb62e) @@ -0,0 +1,34 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2014 Brazil + + 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 +*/ + +#ifndef GRN_MRB_LOGGER_H +#define GRN_MRB_LOGGER_H + +#include "../ctx.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void grn_mrb_logger_init(grn_ctx *ctx); + +#ifdef __cplusplus +} +#endif + +#endif /* GRN_MRB_LOGGER_H */ Modified: lib/mrb/sources.am (+2 -0) =================================================================== --- lib/mrb/sources.am 2014-08-07 12:00:01 +0900 (710ecb5) +++ lib/mrb/sources.am 2014-08-07 12:04:03 +0900 (4b99eae) @@ -17,6 +17,8 @@ libgrnmrb_la_SOURCES = \ mrb_id.h \ mrb_index_column.c \ mrb_index_column.h \ + mrb_logger.c \ + mrb_logger.h \ mrb_obj.c \ mrb_obj.h \ mrb_operator.c \ -------------- next part -------------- HTML����������������������������... 下载