Module: Syslog
| Relationships & Source Files | |
| Namespace Children | |
|
Modules:
| |
|
Classes:
| |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Instance Chain:
|
|
| Defined in: | lib/syslog/jruby.rb, ext/syslog/syslog.c |
Constant Summary
-
FORMAT_STRING =
# File 'lib/syslog/jruby.rb', line 355'%s' -
VERSION =
# File 'ext/syslog/syslog.c', line 579
Syslogmacrosrb_str_new_cstr(SYSLOG_VERSION)
Level - Included
LOG_ALERT, LOG_CRIT, LOG_DEBUG, LOG_EMERG, LOG_ERR, LOG_INFO, LOG_NOTICE, LOG_WARNING
Facility - Included
LOG_AUTH, LOG_AUTHPRIV, LOG_CONSOLE, LOG_CRON, LOG_DAEMON, LOG_FTP, LOG_KERN, LOG_LOCAL0, LOG_LOCAL1, LOG_LOCAL2, LOG_LOCAL3, LOG_LOCAL4, LOG_LOCAL5, LOG_LOCAL6, LOG_LOCAL7, LOG_LPR, LOG_MAIL, LOG_NEWS, LOG_NTP, LOG_SECURITY, LOG_SYSLOG, LOG_USER, LOG_UUCP
Class Attribute Summary
-
.mask
rw
mask.
-
.mask=(priority_mask)
rw
Sets the log priority mask.
-
.opened? ⇒ Boolean
readonly
Is it open?
Class Method Summary
-
.alert(*args)
handy little shortcut for LOG_ALERT as the priority.
-
.close
Close the log close will raise an error if it is already closed.
-
.crit(*args)
handy little shortcut for LOG_CRIT as the priority.
-
.debug(*args)
handy little shortcut for LOG_DEBUG as the priority.
-
.emerg(*args)
handy little shortcut for LOG_EMERG as the priority.
-
.err(*args)
handy little shortcut for LOG_ERR as the priority.
-
.facility
returns the facility of the last open call.
-
.ident
returns the ident of the last open call.
-
.info(*args)
handy little shortcut for LOG_INFO as the priority.
- .inspect
-
.instance
instance# => Syslog Returns the Syslog module. -
.log(*args)
log(Syslog::LOG_CRIT, “The %s is falling!”, “sky”).
-
LOG_MASK(pri)
LOG_MASK(pri).
-
LOG_UPTO(pri)
LOG_UPTO(pri) HACK copied from macro Creates a mask for all priorities up to pri.
-
.notice(*args)
handy little shortcut for LOG_NOTICE as the priority.
-
.open(*args)
open(ident = $0, logopt =
Syslog::LOG_PID|Syslog::LOG_CONS, facility =Syslog::LOG_USER) [{ |syslog| … -
.open!(*args)
(also: .reopen)
like open, but closes it first.
-
.options
returns the options of the last open call.
-
.reopen(*args)
(also: .open!)
Alias for .open!.
-
.warning(*args)
handy little shortcut for LOG_WARNING as the priority.
- .write(pri, format, *args)
Instance Method Summary
Class Attribute Details
.mask (rw)
# File 'lib/syslog/jruby.rb', line 202
static VALUE mSyslog_get_mask(VALUE self)
{
return syslog_opened ? INT2NUM(syslog_mask) : Qnil;
}
.mask=(priority_mask) (rw)
Sets the log priority mask. A method .LOG_UPTO is defined to make it easier to set mask values. Example:
Syslog.mask = Syslog::LOG_UPTO(Syslog::LOG_ERR)
Alternatively, specific priorities can be selected and added together using binary OR. Example:
Syslog.mask = Syslog::LOG_MASK(Syslog::LOG_ERR) | Syslog::LOG_MASK(Syslog::LOG_CRIT)
The priority mask persists through calls to open() and close().
# File 'ext/syslog/syslog.c', line 265
static VALUE mSyslog_set_mask(VALUE self, VALUE mask)
{
if (!syslog_opened) {
rb_raise(rb_eRuntimeError, "must open syslog before setting log mask");
}
setlogmask(syslog_mask = NUM2INT(mask));
return mask;
}
.opened? ⇒ Boolean (readonly)
Is it open?
# File 'lib/syslog/jruby.rb', line 264
static VALUE mSyslog_isopen(VALUE self)
{
return syslog_opened ? Qtrue : Qfalse;
}
Class Method Details
.alert(*args)
handy little shortcut for LOG_ALERT as the priority
.close
Close the log close will raise an error if it is already closed
# File 'lib/syslog/jruby.rb', line 271
static VALUE mSyslog_close(VALUE self)
{
if (!syslog_opened) {
rb_raise(rb_eRuntimeError, "syslog not opened");
}
closelog();
xfree((void *)syslog_ident);
syslog_ident = NULL;
syslog_options = syslog_facility = syslog_mask = -1;
syslog_opened = 0;
return Qnil;
}
.crit(*args)
handy little shortcut for LOG_CRIT as the priority
.debug(*args)
handy little shortcut for LOG_DEBUG as the priority
.emerg(*args)
handy little shortcut for LOG_EMERG as the priority
.err(*args)
handy little shortcut for LOG_ERR as the priority
.facility
returns the facility of the last open call
# File 'lib/syslog/jruby.rb', line 188
static VALUE mSyslog_facility(VALUE self)
{
return syslog_opened ? INT2NUM(syslog_facility) : Qnil;
}
.ident
returns the ident of the last open call
# File 'lib/syslog/jruby.rb', line 176
static VALUE mSyslog_ident(VALUE self)
{
return syslog_opened ? rb_str_new2(syslog_ident) : Qnil;
}
.info(*args)
handy little shortcut for LOG_INFO as the priority
.inspect
[ GitHub ]# File 'lib/syslog/jruby.rb', line 339
def inspect if @opened "<#%s: opened=true, ident=\"%s\", options=%d, facility=%d, mask=%d>" % [self.name, @ident, @options, @facility, @mask] else "<##{self.name}: opened=false>" end end
.instance
instance # => Syslog Returns the Syslog module
# File 'lib/syslog/jruby.rb', line 351
static VALUE mSyslog_instance(VALUE self)
{
return self;
}
.log(*args)
log(Syslog::LOG_CRIT, “The %s is falling!”, “sky”)
Doesn’t take any platform specific printf statements
logs things to $stderr
log(Syslog::LOG_CRIT, "Welcome, %s, to my %s!", "leethaxxor", "lavratory")
# File 'lib/syslog/jruby.rb', line 286
static VALUE mSyslog_log(int argc, VALUE *argv, VALUE self)
{
VALUE pri;
rb_check_arity(argc, 2, UNLIMITED_ARGUMENTS);
argc--;
pri = *argv++;
if (!FIXNUM_P(pri)) {
rb_raise(rb_eTypeError, "type mismatch: %"PRIsVALUE" given", rb_obj_class(pri));
}
syslog_write(FIX2INT(pri), argc, argv);
return self;
}
LOG_MASK(pri)
LOG_MASK(pri)
HACK copied from macro Creates a mask for one priority.
# File 'lib/syslog/jruby.rb', line 327
def LOG_MASK(pri) 1 << pri end
LOG_UPTO(pri)
LOG_UPTO(pri) HACK copied from macro Creates a mask for all priorities up to pri.
# File 'lib/syslog/jruby.rb', line 335
def LOG_UPTO(pri) (1 << ((pri)+1)) - 1 end
.notice(*args)
handy little shortcut for LOG_NOTICE as the priority
# File 'lib/syslog/jruby.rb', line 312
def notice(*args); write(Syslog::LOG_NOTICE, *args); end
.open(*args)
open(ident = $0, logopt = Syslog::LOG_PID | Syslog::LOG_CONS, facility = Syslog::LOG_USER) [{ |syslog| … }]
Opens syslog with the given options and returns the module itself. If a block is given, calls it with an argument of itself. If syslog is already opened, raises RuntimeError.
Examples:
Syslog.open('ftpd', Syslog::LOG_PID | Syslog::LOG_NDELAY, Syslog::LOG_FTP)
open!(ident = $0, logopt = Syslog::LOG_PID | Syslog::LOG_CONS, facility = Syslog::LOG_USER)
reopen(ident = $0, logopt = Syslog::LOG_PID | Syslog::LOG_CONS, facility = Syslog::LOG_USER)
# File 'lib/syslog/jruby.rb', line 219
static VALUE mSyslog_open(int argc, VALUE *argv, VALUE self)
{
VALUE ident, opt, fac;
const char *ident_ptr;
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");
}
ident_ptr = StringValueCStr(ident);
syslog_ident = strdup(ident_ptr);
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) Also known as: .reopen
like open, but closes it first
# File 'lib/syslog/jruby.rb', line 255
static VALUE mSyslog_reopen(int argc, VALUE *argv, VALUE self)
{
mSyslog_close(self);
return mSyslog_open(argc, argv, self);
}
.options
returns the options of the last open call
# File 'lib/syslog/jruby.rb', line 182
static VALUE mSyslog_options(VALUE self)
{
return syslog_opened ? INT2NUM(syslog_options) : Qnil;
}
.reopen(*args) Also known as: .open!
Alias for .open!.
.warning(*args)
handy little shortcut for LOG_WARNING as the priority
# File 'lib/syslog/jruby.rb', line 308
def warning(*args);write(Syslog::LOG_WARNING, *args); end
.write(pri, format, *args)
[ GitHub ]# File 'lib/syslog/jruby.rb', line 356
def write(pri, format, *args) raise "Syslog must be opened before write" unless @opened = format % args Foreign.write(pri, FORMAT_STRING, :string, , :pointer, nil) end