tags:

views:

37

answers:

2

I'm very new playing with syslog.

We have decide to use syslog to track some especial events on our Rails application.

The point is that I don't want to use the default /var/log/system.log file but use a custom one like /var/log/myapp_events.log.

I see that for that I have to define my own facility into the /etc/syslog.conf like this:

myapp_events.* /var/log/myapp_events.log

After restart syslogd I see I can play with it directly into the bash console:

syslog -s -k Facility myapp_events Message "this is my message"

The message appears into the /var/log/myapp_events.log as expected. But I can not reproduce this behavior using the syslog ruby gem, I have tried:

require 'syslog'
Syslog.open('myapp_events', Syslog::LOG_PID | Syslog::LOG_CONS) { |s| s.warning 'this is my message' }  # sends the message to system.log
Syslog.open('myapp_events', Syslog::LOG_PID | Syslog::LOG_CONS, 'myapp_events') { |s| s.warning 'this is my message' }  # error because 'myapp_event' can't be converted to int.

I see that Syslog.open has a third argument wich is the facility but it has to be an integer and what I have is an string.

Any suggestion?

A: 

You might want to look into using Logger, which is very similar to syslog, only it is a bit more user-friendly. It has multiple levels of criticality, like Syslog, and offers log rolling based on size or age.

Greg
The point is that we want to use the `syslog` daemon, so we can use its unix features by free.
fguillen
My point is that Syslog in Ruby is poorly documented. You'll probably need to read the source for it to do much beyond the fundamentals. Logger is a reaction to that and is easier to use and a lot of people use it instead because it is more accessible. I use syslog all the time but still think its a PITA and could do with a major facelift to make it more appealing.
Greg
I have travel deep into the `syslog` ruby implementation and it is used the `syslog` C implementation and there is not any posibility to send to this C function a custom facility, you have to choose between the oficial ones: http://search.cpan.org/~saper/Sys-Syslog/Syslog.pm#Facilities .. think this is the end of the history :)
fguillen
A: 

Definitely the syslog ruby implementation doesn't allow us to use custom facilities.

The syslog ruby implementation is using the syslog C implementation: http://github.com/ruby/ruby/blob/trunk/ext/syslog/syslog.c#L36 .

And the syslog C implementation only allow us to use a very sort list of facilities names: LOG_USER, LOG_MAIL, LOG_DAEMON, LOG_AUTH, LOG_SYSLOG, LOG_LPR, LOG_NEWS, LOG_UUCP, UUCP , LOG_CRON, LOG_AUTHPRIV, LOG_FTP, LOG_LOCAL0, LOG_LOCAL1, LOG_LOCAL2, LOG_LOCAL3, LOG_LOCAL4, LOG_LOCAL5, LOG_LOCAL6, LOG_LOCAL7.

So at the end what I did was use one of the LOG_LOCALX facilities that are already there for personal uses.

Now I can configure syslog like this:

# /etc/syslog.conf
local5.*    /var/log/myapp_events.log

And in Ruby do this:

Syslog.open('myapp', Syslog::LOG_PID, Syslog::LOG_LOCAL5) { |s| s.info 'this is my message' }

I think is the way that syslog wants you to define custom facilities.

fguillen