Class: Syndi::Logger

Inherits:
Object
  • Object
show all
Defined in:
ext/csyndi/logger.c

Instance Method Summary collapse

Constructor Details

#initializeSyndi::Logger

Constructs a new Syndi::Logger instance.



107
108
109
110
111
# File 'ext/csyndi/logger.c', line 107

static VALUE logger_init(VALUE self)
{
    log_dircheck();
    return self;
}

Instance Method Details

#debug(message) ⇒ Object



240
241
242
243
# File 'ext/csyndi/logger.c', line 240

static VALUE logger_debug(VALUE self, VALUE message)
{
    return logger_verbose(self, message, INT2FIX(3));
}

#deprecate(message) ⇒ nil

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

Parameters:

  • message (String)

    The notice regarding usage of a deprecated method.

Returns:

  • (nil)


179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'ext/csyndi/logger.c', line 179

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(message) ⇒ nil

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

Parameters:

  • message (String)

    The error message to be reported.

  • backtrace (Boolean)

    Whether to output a backtrace.

Returns:

  • (nil)


136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'ext/csyndi/logger.c', line 136

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(message) ⇒ nil

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

Parameters:

  • message (String)

    The fatal error message to be reported.

Returns:

  • (nil)


119
120
121
122
123
124
125
126
# File 'ext/csyndi/logger.c', line 119

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(message) ⇒ nil

This will log message as an informative message.

Parameters:

  • message (String)

    The information to be reported.

Returns:

  • (nil)


202
203
204
205
206
207
208
# File 'ext/csyndi/logger.c', line 202

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(message, level) ⇒ nil

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

Parameters:

  • message (String)

    The message to be reported.

  • level (Integer)

    The level of verbosity. We recommend +VSIMPLE+, +VUSEFUL+, or +VNOISY+.

Returns:

  • (nil)


220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'ext/csyndi/logger.c', line 220

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(message) ⇒ nil

This will log message as a warning.

Parameters:

  • message (String)

    The admonitory message to be reported.

Returns:

  • (nil)


165
166
167
168
169
170
171
# File 'ext/csyndi/logger.c', line 165

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;
}