Search code examples
rubysyslog

Syslog error wih Windows


I'm trying to run a script using syslog, but i always get an error saying that could not possible find syslog.

C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in require': cannot load such file -- syslog (LoadError) from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:i nrequire' from script.rb:1:in `'

My Script is:

require 'syslog'

def log(message)

  # $0 is the current script name

  Syslog.open($0, Syslog::LOG_PID | Syslog::LOG_CONS) { |s| s.warning message }

end


log("Warning from ruby!")

Solution

  • We're currently trying to port our app to Windows, and ran into this same thing. Bottom line, out-of-the-box Ruby syslog won't work on Windows (as hinted by https://www.ruby-forum.com/topic/78859#129379) because it relies on some Unix functions (namely syslog(3))

    Others suggest https://rubygems.org/gems/win32-eventlog/versions/0.6.3 as a means to let you tap into the Windows Event Log API.

    Alternatively, if you don't need to tap into the system, you could look into Logger