Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
syslog protocol for ruby
branch: master

This branch is 17 commits behind eric:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
README.rdoc
Rakefile
syslogproto.gemspec

README.rdoc

Syslog protocol

roughly conforms to the murky shade of grey known as www.faqs.org/rfcs/rfc3164.html

Examples

Manipulate packets manually

require 'syslogproto'
p = SyslogProto::Packet.new
p.hostname = "space_station"
p.facility = "kern"
p.severity = "warn"
p.msg = "flight control broken"
p.to_s
# => "<4>Aug  1 14:01:17 space_station flight control broken"
p.pri
# => 4
p.facility
# => 0
p.facility_name
# => "kern"
p.severity_name
# => "warn"
p.warn?
# => true
p.info?
# => false

Use a Logger to generate packets

require 'syslogproto'
logger = SyslogProto::Logger.new("space_station", "uucp")
logger.debug("looking for uucp on board the space station")
# => "<67>Aug  1 14:02:29 space_station looking for uucp on board the space station"
logger.emerg("omg we cant find uucp on the space station")
# => "<64>Aug  1 14:03:56 space_station omg we cant find uucp on the space station"

Parse packets

require 'syslogproto'
p = SyslogProto.parse("<34>Oct 11 22:14:15 space_station space is really getting to me")
p.facility
# => 4
p.severity_name
# => "crit"
p.time
# => Sun Oct 11 22:14:15 -0700 2009
p.msg
# => "space is really getting to me"

It yells at you for trying to abuse the protocol

p = SyslogProto::Packet.new
p.facility = 34534534
# => ArgumentError: Facility must be within 0-23
p.hostname = "my host"
# => ArgumentError: Hostname may not contain spaces
p.hostname = "h\000stname"
# => ArgumentError: Hostname may only contain ASCII characters 33-126
# ...etc.
# It will also unintelligently truncate messages > 1024 bytes so beware.

Caveats

Syslog is a terrible and loosely defined protocol. Many devices and programs do not conform to it and so their packets may not be parsed correctly by this interpretation, nor may the packets generated by this necessarily be recognized by other devices or programs ;)

This is probably wrong and buggy, and i know the code is ugly, thanks.

Good luck.

Something went wrong with that request. Please try again.