In Files

  • syslog/syslog.c

Class/Module Index [+]

Quicksearch

Syslog

Init for package syslog

Public Class Methods

LOG_MASK(p1) click to toggle source
 
               static VALUE mSyslogConstants_LOG_MASK(VALUE klass, VALUE pri)
{
    return INT2FIX(LOG_MASK(NUM2INT(pri)));
}
            
LOG_UPTO(p1) click to toggle source
 
               static VALUE mSyslogConstants_LOG_UPTO(VALUE klass, VALUE pri)
{
    return INT2FIX(LOG_UPTO(NUM2INT(pri)));
}
            
close() click to toggle source

Syslog module methods

 
               static VALUE mSyslog_close(VALUE self)
{
    rb_secure(4);
    if (!syslog_opened) {
        rb_raise(rb_eRuntimeError, "syslog not opened");
    }

    closelog();

    free((void *)syslog_ident);
    syslog_ident = NULL;
    syslog_options = syslog_facility = syslog_mask = -1;
    syslog_opened = 0;

    return Qnil;
}
            
facility() click to toggle source
 
               static VALUE mSyslog_facility(VALUE self)
{
    return syslog_opened ? INT2NUM(syslog_facility) : Qnil;
}
            
ident() click to toggle source
 
               static VALUE mSyslog_ident(VALUE self)
{
    return syslog_opened ? rb_str_new2(syslog_ident) : Qnil;
}
            
inspect() click to toggle source
 
               static VALUE mSyslog_inspect(VALUE self)
{
    char buf[1024];

    Check_Type(self, T_MODULE);

    if (syslog_opened) {
        snprintf(buf, sizeof(buf),
          "<#%s: opened=true, ident=\"%s\", options=%d, facility=%d, mask=%d>",
          rb_class2name(self),
          syslog_ident,
          syslog_options,
          syslog_facility,
          syslog_mask);
    } else {
        snprintf(buf, sizeof(buf),
          "<#%s: opened=false>", rb_class2name(self));
    }

    return rb_str_new2(buf);
}
            
instance() click to toggle source
 
               static VALUE mSyslog_instance(VALUE self)
{
    return self;
}
            
log(*args) click to toggle source
 
               static VALUE mSyslog_log(int argc, VALUE *argv, VALUE self)
{
    VALUE pri;

    if (argc < 2) {
        rb_raise(rb_eArgError, "wrong number of arguments (%d for 2+)", argc);
    }

    argc--;
    pri = *argv++;

    if (!FIXNUM_P(pri)) {
      rb_raise(rb_eTypeError, "type mismatch: %s given", rb_class2name(CLASS_OF(pri)));
    }

    syslog_write(FIX2INT(pri), argc, argv);

    return self;
}
            
mask() click to toggle source
 
               static VALUE mSyslog_get_mask(VALUE self)
{
    return syslog_opened ? INT2NUM(syslog_mask) : Qnil;
}
            
mask=(p1) click to toggle source
 
               static VALUE mSyslog_set_mask(VALUE self, VALUE mask)
{
    rb_secure(4);
    if (!syslog_opened) {
        rb_raise(rb_eRuntimeError, "must open syslog before setting log mask");
    }

    setlogmask(syslog_mask = NUM2INT(mask));

    return mask;
}
            
open(p1 = v1, p2 = v2, p3 = v3) click to toggle source
 
               static VALUE mSyslog_open(int argc, VALUE *argv, VALUE self)
{
    VALUE ident, opt, fac;

    if (syslog_opened) {
        rb_raise(rb_eRuntimeError, "syslog already open");
    }

    rb_scan_args(argc, argv, "03", &ident, &opt, &fac);

    if (NIL_P(ident)) {
        ident = rb_gv_get("$0");
    }
    SafeStringValue(ident);
    syslog_ident = strdup(RSTRING_PTR(ident));

    if (NIL_P(opt)) {
        syslog_options = LOG_PID | LOG_CONS;
    } else {
        syslog_options = NUM2INT(opt);
    }

    if (NIL_P(fac)) {
        syslog_facility = LOG_USER;
    } else {
        syslog_facility = NUM2INT(fac);
    }

    openlog(syslog_ident, syslog_options, syslog_facility);

    syslog_opened = 1;

    setlogmask(syslog_mask = setlogmask(0));

    /* be like File.new.open {...} */
    if (rb_block_given_p()) {
        rb_ensure(rb_yield, self, mSyslog_close, self);
    }

    return self;
}
            
open!(*args) click to toggle source
 
               static VALUE mSyslog_reopen(int argc, VALUE *argv, VALUE self)
{
    mSyslog_close(self);

    return mSyslog_open(argc, argv, self);
}
            
opened?() click to toggle source
 
               static VALUE mSyslog_isopen(VALUE self)
{
    return syslog_opened ? Qtrue : Qfalse;
}
            
options() click to toggle source
 
               static VALUE mSyslog_options(VALUE self)
{
    return syslog_opened ? INT2NUM(syslog_options) : Qnil;
}
            
reopen(*args) click to toggle source
 
               static VALUE mSyslog_reopen(int argc, VALUE *argv, VALUE self)
{
    mSyslog_close(self);

    return mSyslog_open(argc, argv, self);
}