Wednesday, August 8, 2007

Ruby and Syslog

As others have also pointed out there is no ri documentation for the syslog module but there is a lot of useful stuff in the ext/syslog directory.

But here is the most basic example I can come up with:


irb(main):007:0> mdfranz@franz-t61:~$ irb
irb(main):001:0> require 'syslog'
=> true
irb(main):002:0> Syslog.open('labradoodle')
=> <#Syslog: opened=true, ident="labradoodle", options=3, facility=8, mask=255>
irb(main):003:0> Syslog.crit('w00f w00f')
=> <#Syslog: opened=true, ident="labradoodle", options=3, facility=8, mask=255>
irb(main):004:0> Syslog.close
=> nil
irb(main):005:0> Syslog.crit('w00f w00f')
RuntimeError: must open syslog before write
from (irb):5:in `crit'
from (irb):5
from :0

And /var/log/syslog

Aug 8 10:03:22 franz-t61 labradoodle[3688]: w00f w00f
Aug 8 10:04:24 franz-t61 kernel: [ 9700.304000] iwl4965: REPLY_ADD_STA failed
Aug 8 10:06:27 franz-t61 kernel: [ 9823.088000] iwl4965: REPLY_ADD_STA failed

No comments: