I have some handlers and a mutator running inside the sensu server as extensions. I want my extensions to log to a separate file from the rest of the sensu server logs. What is the best way to do this?
My initial approach was to define a logger in the extension’s post_init() method() using the Ruby’s built-in Logger API (See http://www.ruby-doc.org/stdlib-2.0.0/libdoc/logger/rdoc/Logger.html). Unfortunately, the logger worked fine inside post_init(), but when I invoked the logger from the extension’s run() method, the log could not be written to. Error messages:
log shifting failed. closed stream
log writing failed. closed stream
A question on stack overflow indicated this could be a side effect of the Daemons gem, which Sensu appears to use. (See http://stackoverflow.com/questions/14808226/ruby-logger-and-daemons)
I next tried to lazy initialize my logger inside the run method, but that did not help.
I can see that there is a sensu-logger gem available (see https://github.com/sensu/sensu-logger) but I was not able to find clear examples on how to use it, nor is it obvious that I’d have different results using this over Ruby’s built-in logging API.
Any advice would be appreciated.