Daemons::SyslogIO is a class that allows you to use syslog through an IO-like interface. You can wrap standard streams like $stdout and $stderr so that all output from your application is automatically sent to the system logger.
When initializing, you can provide an identifier, syslog facility, log level, syslog options, and an optional IO object for passthrough (where text is written to both syslog and the provided IO).
Note: Multiple SyslogIO objects share the same underlying syslog connection. The identifier is shared and will be set to the value of the last object created. Syslog options are merged across all objects, but facility and level are distinct per instance.
require 'syslogio'
# Redirect stdout to syslog with info level
$stdout = Daemons::SyslogIO.new("myapp", :local0, :info, $stdout)
# Redirect stderr to syslog with error level
$stderr = Daemons::SyslogIO.new("myapp", :local0, :err, $stderr)
$stdout.puts "This is a message"
$stderr.puts "This is an error"
# Errors will also be captured by the $stderr SyslogIO
raise StandardError, 'This will get written through the SyslogIO for $stderr'