Method: Syslog.open
- Defined in:
- syslog.c
.open(ident, options, facility) ⇒ Object
:yields: syslog
Open the syslog facility. Raises a runtime exception if it is already open.
Can be called with or without a code block. If called with a block, the Syslog object created is passed to the block.
If the syslog is already open, raises a RuntimeError.
ident is a String which identifies the calling program.
options is the logical OR of any of the following:
- LOG_CONS
If there is an error while sending to the system logger, write directly to the console instead.
- LOG_NDELAY
Open the connection now, rather than waiting for the first message to be written.
- LOG_NOWAIT
Don't wait for any child processes created while logging messages. (Has no effect on Linux.)
- LOG_ODELAY
Opposite of LOG_NDELAY; wait until a message is sent before opening the connection. (This is the default.)
- LOG_PERROR
Print the message to stderr as well as sending it to syslog. (Not in POSIX.1-2001.)
- LOG_PID
Include the current process ID with each message.
facility describes the type of program opening the syslog, and is
the logical OR of any of the following which are defined for the host OS:
- LOG_AUTH
Security or authorization. Deprecated, use LOG_AUTHPRIV instead.
- LOG_AUTHPRIV
Security or authorization messages which should be kept private.
- LOG_CONSOLE
System console message.
- LOG_CRON
System task scheduler (cron or at).
- LOG_DAEMON
A system daemon which has no facility value of its own.
- LOG_FTP
An FTP server.
- LOG_KERN
A kernel message (not sendable by user processes, so not of much use to Ruby, but listed here for completeness).
- LOG_LPR
Line printer subsystem.
- LOG_MAIL
Mail delivery or transport subsystem.
- LOG_NEWS
Usenet news system.
- LOG_NTP
Network Time Protocol server.
- LOG_SECURITY
General security message.
- LOG_SYSLOG
Messages generated internally by syslog.
- LOG_USER
Generic user-level message.
- LOG_UUCP
UUCP subsystem.
- LOG_LOCAL0 to LOG_LOCAL7
Locally-defined facilities.
Example:
Syslog.open("webrick", Syslog::LOG_PID, Syslog::LOG_DAEMON | Syslog::LOG_LOCAL3)
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'syslog.c', line 152
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;
}
|