Syslog facility

Hi All,

I am having trouble with pointing the syslog messages to a particular
facility. Is this the right way to point it at facility local1:

Syslog.open('name_of_prog', facility = Syslog::LOG_LOCAL1)
Syslog.log(Syslog::LOG_NOTICE, "message_goes_here")
Syslog.close

I would really appreciate your help!

Thanks,
Greg

greg wrote:

Hi All,

I am having trouble with pointing the syslog messages to a particular
facility. Is this the right way to point it at facility local1:

Syslog.open('name_of_prog', facility = Syslog::LOG_LOCAL1)
Syslog.log(Syslog::LOG_NOTICE, "message_goes_here")
Syslog.close

I would really appreciate your help!

The way I do it is:

Exactly what I needed! Thanks!

I closed the log with `Syslog::close’. Is this the way you do it?

Thanks in advance!

greg wrote:

Exactly what I needed! Thanks!

I closed the log with `Syslog::close’. Is this the way you do it?

Thanks in advance!

I don’t bother. I generally use syslog with programs that run
indefinitely
and want the logging to continue until the system is rebooted or the
process is terminated on purpose.


require ‘syslog’

$log = Syslog.open(‘progname’, Syslog::LOG_PID, Syslog::LOG_LOCAL1)

$log.info(“messsage”)

Does anyone know if this works on OS X? Where would I look for the
output?


Craig B.

AIM: kreiggers

$log = Syslog.open(‘progname’, Syslog::LOG_PID, Syslog::LOG_LOCAL1)
AIM: kreiggers

OS X uses syslog, so it sure works on OS X.

Where things go is configured in /etc/syslog.conf

I don’t believe I’ve edited this file on my wife’s iBook, and line 2
there
shows:

*.notice;authpriv,remoteauth,ftp,install.none;kern.debug;mail.crit
/var/log/system.log

So anything with a level of larger than or equal to notice will go to
/var/log/system.log

Testing:

$ uname -a
Darwin fwindt.lan 8.10.0 Darwin Kernel Version 8.10.0: Wed May 23
16:50:59
PDT 2007; root:xnu-792.21.3~1/RELEASE_PPC Power Macintosh powerpc
$ irb
reqirb(main):001:0> require ‘syslog’
=> true
irb(main):002:0> log = Syslog.open(‘progname’, Syslog::LOG_PID,
Syslog::LOG_LOCAL1)
=> <#Syslog: opened=true, ident=“progname”, options=1, facility=136,
mask=255>
irb(main):003:0> log.err(“my message”)
=> <#Syslog: opened=true, ident=“progname”, options=1, facility=136,
mask=255>
irb(main):004:0> exit
$ grep “my message” /var/log/syslog
Sep 2 13:25:13 fwindt-2 progname[891]: my message

You can redirect to special log files like this:
Looking through syslog.conf, it appears as if OS X only uses local0
(it’s
used for ipfw, the firewall). So you could use local1 as in the example,
and
edit your syslog.conf to contain a line such as “local1.*
/var/log/myapp.log” to have your logs written to that file as well. Just
to
mention it, there’s no way of keeping other apps from using that
facility as
well.
I believe you need to send a HUP to the syslog daemon for it to parse
changes to the config file.

HTH,

Felix