class Syndi::Logger

Public Class Methods

new() click to toggle source

@overload initialize()

Constructs a new Syndi::Logger instance.

@return [Syndi::Logger]
static VALUE logger_init(VALUE self)
{
    log_dircheck();
    return self;
}

Public Instance Methods

debug(p1) click to toggle source
static VALUE logger_debug(VALUE self, VALUE message)
{
    return logger_verbose(self, message, INT2FIX(3));
}
deprecate(p1) click to toggle source

@overload deprecate(message)

This will call Kernel#warn with the notice of deprecation.

@param [String] message The notice regarding usage of a deprecated method.
@return [nil]
static VALUE logger_deprecate(VALUE self, VALUE message)
{
    VALUE backtrace;
    VALUE notice;

    notice = rb_str_new("DEPRECATION WARNING: ", 21);
    rb_str_append(notice, message);

    rb_funcall(rb_cObject, SYM(warn), 1, notice);
        
    backtrace = rb_funcall(rb_cObject, SYM(caller), 0);
    fprintf(stderr, "Backtrace:%s", OS_LINE_TERM);
    rb_funcall(rb_stderr, SYM(puts), 1, backtrace);

    return Qnil;
}
error(p1, p2 = v2) click to toggle source

@overload error(message)

This will log `message` as an error, optionally also outputting `backtrace`,
the data for which shall be obtained from Kernel#caller.

@param [String] message The error message to be reported.
@param [Boolean] backtrace Whether to output a backtrace.
@return [nil]
static VALUE logger_error(int argc, VALUE *argv, VALUE self)
{
    VALUE message;
    VALUE backtrace;
    VALUE bt_bool;
    char *msg;

    rb_scan_args(argc, argv, "11", &message, &bt_bool);

    msg = RSTRING_PTR(message);
    log_out2file("ERROR", msg);
    log_out2scrn(TYPE_ERROR, msg, 0);

    if (bt_bool == Qtrue)
    {
        backtrace = rb_funcall(rb_cObject, SYM(caller), 0);
        fprintf(stderr, "Backtrace:%s", OS_LINE_TERM);
        rb_funcall(rb_stderr, SYM(puts), 1, backtrace);
    }
    
    return Qnil;
}
fatal(p1) click to toggle source

@overload fatal(message)

This will log `message` as a fatal error, as well as kill the program.

@param [String] message The fatal error message to be reported.
@return [nil]
static VALUE logger_fatal(VALUE self, VALUE message)
{
    char *msg = RSTRING_PTR(message);
    log_out2file("FATAL ERROR", msg);
    log_out2scrn(TYPE_FATAL, msg, 0);
    rb_exit(1);
    return Qnil;
}
info(p1) click to toggle source

@overload info(message)

This will log `message` as an informative message.

@param [String] message The information to be reported.
@return [nil]
static VALUE logger_info(VALUE self, VALUE message)
{
    char *msg = RSTRING_PTR(message);
    log_out2file("INFO", msg);
    log_out2scrn(TYPE_INFO, msg, 0);
    return Qnil;
}
verbose(p1, p2) click to toggle source

@overload verbose(message, level)

Yield a message of verbosity magic. This will execute any block it is
passed (*implicit!*).

@param [String] message The message to be reported.
@param [Integer] level The level of verbosity. We recommend +VSIMPLE+,
   +VUSEFUL+, or +VNOISY+.

@return [nil]
static VALUE logger_verbose(VALUE self, VALUE message, VALUE level)
{
    char *msg = RSTRING_PTR(message);
    int vrb = FIX2INT(level);

    /* check verbosity */
    if (FIX2INT(rb_gv_get("$VERBOSITY")) < vrb)
        return Qnil;

    /* log */
    log_out2file("DEBUG", msg);
    log_out2scrn(TYPE_DEBUG, msg, vrb);

    /* execute the block */
    if (rb_block_given_p())
        rb_yield(Qnil);

    return Qnil;
}
warn(p1) click to toggle source

@overload warn(message)

This will log `message` as a warning.

@param [String] message The admonitory message to be reported.
@return [nil]
static VALUE logger_warn(VALUE self, VALUE message)
{
    char *msg = RSTRING_PTR(message);
    log_out2file("WARNING", msg);
    log_out2scrn(TYPE_WARNING, msg, 0);
    return Qnil;
}