# Syslog facility

**URL:** <https://www.ruby-forum.com/t/syslog-facility/113453>\
**Category:** Ruby\
**Created:** [August 31, 2007, 8:06am UTC](https://www.ruby-forum.com/t/syslog-facility/113453 "2007-08-31T08:06:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [August 31, 2007, 8:06am UTC](https://www.ruby-forum.com/t/syslog-facility/113453/1 "2007-08-31T08:06:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [September 1, 2007, 3:24am UTC](https://www.ruby-forum.com/t/syslog-facility/113453/2 "2007-09-01T03:24:56Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [September 1, 2007, 4:36am UTC](https://www.ruby-forum.com/t/syslog-facility/113453/3 "2007-09-01T04:36:01Z")

</div>

Exactly what I needed! Thanks!

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

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [September 1, 2007, 3:14pm UTC](https://www.ruby-forum.com/t/syslog-facility/113453/4 "2007-09-01T15:14:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [September 2, 2007, 10:04pm UTC](https://www.ruby-forum.com/t/syslog-facility/113453/5 "2007-09-02T22:04:04Z")

</div>

> * * *
> 
> ## 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

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [September 2, 2007, 10:33pm UTC](https://www.ruby-forum.com/t/syslog-facility/113453/6 "2007-09-02T22:33:21Z")

</div>

> > $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
