Sha256: 31c6945c34e6a7c47701e3505addadac2aa48ad1ce1f7c6debde158bd7017014
Contents?: true
Size: 666 Bytes
Versions: 1
Compression:
Stored size: 666 Bytes
Contents
require 'socket' class SyslogLogger SYSLOG_IP = '127.0.0.1' SYSLOG_PORT = 514 def initialize(error_log_file = nil) @udp = UDPSocket.new @error_log_file = error_log_file end def <<(msg) send_logs_to_syslog(msg) end def puts(msg) send_logs_to_syslog(msg) end def flush; end private def send_logs_to_syslog(log_msg) # max packet size to send is 9210 chars, so do it in chunks chunk_string(log_msg).each do |chunk| @udp.send(log_msg[0..9210], 0, SYSLOG_IP, SYSLOG_PORT) end @error_log_file.write(log_msg) unless @error_log_file.nil? end def chunk_string(msg) msg.scan(/.{1,9000}/) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sinatra-syslog-logger-0.1.0 | lib/sinatra-syslog-logger/logger.rb |