Class: SyslogClient
- Inherits:
-
Object
- Object
- SyslogClient
- Defined in:
- lib/scribble-client/syslog_client.rb
Instance Method Summary collapse
-
#initialize(server = nil) ⇒ SyslogClient
constructor
A new instance of SyslogClient.
- #syslog(facility, priority, message) ⇒ Object
Constructor Details
#initialize(server = nil) ⇒ SyslogClient
Returns a new instance of SyslogClient.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/scribble-client/syslog_client.rb', line 6 def initialize(server = nil) raise "Don't support system logger (yet)" unless server (host,port) = server.split(/:/) @socket = UDPSocket.new @socket.connect(host,port) #Allow for really big log lines @socket.setsockopt(Socket::SOL_SOCKET,Socket::SO_SNDBUF,24000) @error_count = 0 end |
Instance Method Details
#syslog(facility, priority, message) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/scribble-client/syslog_client.rb', line 18 def syslog(facility,priority,) #Build the header fpnum = ((facility & 0x1F) << 3) | (priority & 0x07) host = Socket.gethostname tim = Time.now.strftime("%b %d %H:%M:%S") #tim = Time.now.xmlschema buf = "<#{fpnum}>#{tim} #{host} thetag #{}" begin @socket.send(buf,0) rescue Exception => e @error_count += 1 @last_error = e end end |