Esempio n. 1
0
static mrb_value
query_logger_log_raw(mrb_state *mrb, mrb_value self)
{
  grn_ctx *ctx = (grn_ctx *)mrb->ud;
  mrb_int flag;
  char *mark;
  char *message;
  mrb_int message_size;

  mrb_get_args(mrb, "izs", &flag, &mark, &message, &message_size);
  grn_query_logger_put(ctx, flag, mark,
                       "%.*s", (int)message_size, message);

  return self;
}
Esempio n. 2
0
/*
 * Logs a message.
 *
 * @overload log(message, options={})
 *   @param message [String] The log message.
 *   @param options [::Hash]
 *   @option options :context [Groonga::Context] (Groonga::Context.default)
 *     The context for the message.
 *   @option options :flags [nil, Integer, String] (0)
 *     The flags for the message.
 *
 *     The flags are passed to query logger. You can custom query
 *     logger behavior by the flags. For example, you can omit elapsed
 *     time by passing `Groonga::QueryLogger::COMMAND` flag or
 *     `Groonga::QueryLogger::DESTINATION`.
 *
 *     If `:flags` value is `String`, parsed by
 *     {Groonga::QueryLogger.parse}.
 *
 *     `nil` equals to `0`.
 *   @option options :mark [String] ("")
 *     The mark for the message.
 *
 *     Normally, a character is used as a mark such as `":"`, `"<"` and `">"`.
 *   @return [void]
 *
 * @since 5.0.2
 */
static VALUE
rb_grn_query_logger_s_log (int argc, VALUE *argv, VALUE klass)
{
    VALUE rb_message;
    const char *message;
    VALUE rb_context = Qnil;
    grn_ctx *context;
    VALUE rb_flags;
    unsigned int flags = GRN_QUERY_LOG_NONE;
    VALUE rb_mark;
    const char *mark = "";
    VALUE rb_options;

    rb_scan_args(argc, argv, "11", &rb_message, &rb_options);

    message = StringValueCStr(rb_message);

    rb_grn_scan_options(rb_options,
                        "context", &rb_context,
                        "flags",   &rb_flags,
                        "mark",    &rb_mark,
                        NULL);

    context = rb_grn_context_ensure(&rb_context);

    if (!NIL_P(rb_flags)) {
        flags = rb_funcall(mGrnQueryLoggerFlags, id_parse, 2,
                           rb_flags, UINT2NUM(flags));
    }
    if (!NIL_P(rb_mark)) {
        mark = StringValueCStr(rb_mark);
    }

    grn_query_logger_put(context, flags, mark, "%s", message);

    return Qnil;
}