New logger in sensu extension -- "log shifting failed", "log writing failed"

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.

Thanks!

-Travis

Hi Travis,

Sensu does not use the daemons gem. You probably don’t want to use Ruby’s Logger in the event loop. You can find the Sensu logger docs here https://github.com/sensu/sensu-logger#usagehttp://www.rubydoc.info/github/sensu/sensu-logger/Sensu/Logger Sensu services do the following for setup https://github.com/sensu/sensu/blob/master/lib/sensu/daemon.rb#L46-L49

Sean.

···

On Mon, Nov 10, 2014 at 8:24 PM, Travis Bear travis.bear@gmail.com wrote:

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.

Thanks!

-Travis

It’s not obvious that I can control the message format using the sensu-logging gem. (Config options appear to include log_file and log_level only) I need to get the logged messages out of .json format. Is this supported?

Is it okay to have multiple sensu-loggers defined inside a single Sensu server process?

Thanks!

-Travis

···

On Monday, November 10, 2014 8:30:15 PM UTC-8, portertech wrote:

Hi Travis,

Sensu does not use the daemons gem. You probably don’t want to use Ruby’s Logger in the event loop. You can find the Sensu logger docs here https://github.com/sensu/sensu-logger#usagehttp://www.rubydoc.info/github/sensu/sensu-logger/Sensu/Logger Sensu services do the following for setup https://github.com/sensu/sensu/blob/master/lib/sensu/daemon.rb#L46-L49

Sean.

On Mon, Nov 10, 2014 at 8:24 PM, Travis Bear travi...@gmail.com wrote:

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.

Thanks!

-Travis

Sensu::Logger only supports the JSON format. You can have as many instances of the logger as you need. The main instance, used by the Sensu process, is available to every extension, logger() or @logger.

···

On Nov 10, 2014 8:48 PM, “Travis Bear” travis.bear@gmail.com wrote:

It’s not obvious that I can control the message format using the sensu-logging gem. (Config options appear to include log_file and log_level only) I need to get the logged messages out of .json format. Is this supported?

Is it okay to have multiple sensu-loggers defined inside a single Sensu server process?

Thanks!

-Travis

On Monday, November 10, 2014 8:30:15 PM UTC-8, portertech wrote:

Hi Travis,

Sensu does not use the daemons gem. You probably don’t want to use Ruby’s Logger in the event loop. You can find the Sensu logger docs here https://github.com/sensu/sensu-logger#usagehttp://www.rubydoc.info/github/sensu/sensu-logger/Sensu/Logger Sensu services do the following for setup https://github.com/sensu/sensu/blob/master/lib/sensu/daemon.rb#L46-L49

Sean.

On Mon, Nov 10, 2014 at 8:24 PM, Travis Bear travi...@gmail.com wrote:

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.

Thanks!

-Travis

From looking at the sensu-logger source code, I’m not sure it’s possible to have multiple instances of the logger; they all return the same @stream. I tested this out by creating a new sensu-logger in my extension. Unfortunately the new sensu-logger had the same object_id as the existing one, and logged messages to the same file. Are there any working examples of extensions using different loggers than the main sensu server logger which I could look at?

Thanks!

-Travis

···

On Monday, November 10, 2014 8:54:22 PM UTC-8, portertech wrote:

Sensu::Logger only supports the JSON format. You can have as many instances of the logger as you need. The main instance, used by the Sensu process, is available to every extension, logger() or @logger.

On Nov 10, 2014 8:48 PM, “Travis Bear” travi...@gmail.com wrote:

It’s not obvious that I can control the message format using the sensu-logging gem. (Config options appear to include log_file and log_level only) I need to get the logged messages out of .json format. Is this supported?

Is it okay to have multiple sensu-loggers defined inside a single Sensu server process?

Thanks!

-Travis

On Monday, November 10, 2014 8:30:15 PM UTC-8, portertech wrote:

Hi Travis,

Sensu does not use the daemons gem. You probably don’t want to use Ruby’s Logger in the event loop. You can find the Sensu logger docs here https://github.com/sensu/sensu-logger#usagehttp://www.rubydoc.info/github/sensu/sensu-logger/Sensu/Logger Sensu services do the following for setup https://github.com/sensu/sensu/blob/master/lib/sensu/daemon.rb#L46-L49

Sean.

On Mon, Nov 10, 2014 at 8:24 PM, Travis Bear travi...@gmail.com wrote:

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.

Thanks!

-Travis

Hey Travis,

You can use https://github.com/sensu/sensu-logger/blob/master/lib/sensu/logger.rb#L12

Sean.

···

On Tue, Nov 11, 2014 at 11:05 AM, Travis Bear travis.bear@gmail.com wrote:

From looking at the sensu-logger source code, I’m not sure it’s possible to have multiple instances of the logger; they all return the same @stream. I tested this out by creating a new sensu-logger in my extension. Unfortunately the new sensu-logger had the same object_id as the existing one, and logged messages to the same file. Are there any working examples of extensions using different loggers than the main sensu server logger which I could look at?

Thanks!

-Travis

On Monday, November 10, 2014 8:54:22 PM UTC-8, portertech wrote:

Sensu::Logger only supports the JSON format. You can have as many instances of the logger as you need. The main instance, used by the Sensu process, is available to every extension, logger() or @logger.

On Nov 10, 2014 8:48 PM, “Travis Bear” travi...@gmail.com wrote:

It’s not obvious that I can control the message format using the sensu-logging gem. (Config options appear to include log_file and log_level only) I need to get the logged messages out of .json format. Is this supported?

Is it okay to have multiple sensu-loggers defined inside a single Sensu server process?

Thanks!

-Travis

On Monday, November 10, 2014 8:30:15 PM UTC-8, portertech wrote:

Hi Travis,

Sensu does not use the daemons gem. You probably don’t want to use Ruby’s Logger in the event loop. You can find the Sensu logger docs here https://github.com/sensu/sensu-logger#usagehttp://www.rubydoc.info/github/sensu/sensu-logger/Sensu/Logger Sensu services do the following for setup https://github.com/sensu/sensu/blob/master/lib/sensu/daemon.rb#L46-L49

Sean.

On Mon, Nov 10, 2014 at 8:24 PM, Travis Bear travi...@gmail.com wrote:

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.

Thanks!

-Travis

Hi Sean,

I tried to use that API, but it caused the sensu server to fail to start. Not surprisingly, since the problem was a logging initialization failure, there was nothing in the server log to indicate what went wrong.

I added some debug output to my local copy of /opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-logger-1.0.0/lib/sensu/logger.rb. The line that’s breaking is line 18 of logger.rb.

@stream.reopen(options[:log_file])

It’s not clear why; I’ve verified the value of options[:log_file] exists and is writable by the sensu user, and that the log disk partition is not full.

Thanks!

-Travis

···

On Tue, Nov 11, 2014 at 11:07 AM, Sean Porter portertech@gmail.com wrote:

Hey Travis,

You can use https://github.com/sensu/sensu-logger/blob/master/lib/sensu/logger.rb#L12

Sean.

On Tue, Nov 11, 2014 at 11:05 AM, Travis Bear travis.bear@gmail.com wrote:

From looking at the sensu-logger source code, I’m not sure it’s possible to have multiple instances of the logger; they all return the same @stream. I tested this out by creating a new sensu-logger in my extension. Unfortunately the new sensu-logger had the same object_id as the existing one, and logged messages to the same file. Are there any working examples of extensions using different loggers than the main sensu server logger which I could look at?

Thanks!

-Travis

On Monday, November 10, 2014 8:54:22 PM UTC-8, portertech wrote:

Sensu::Logger only supports the JSON format. You can have as many instances of the logger as you need. The main instance, used by the Sensu process, is available to every extension, logger() or @logger.

On Nov 10, 2014 8:48 PM, “Travis Bear” travi...@gmail.com wrote:

It’s not obvious that I can control the message format using the sensu-logging gem. (Config options appear to include log_file and log_level only) I need to get the logged messages out of .json format. Is this supported?

Is it okay to have multiple sensu-loggers defined inside a single Sensu server process?

Thanks!

-Travis

On Monday, November 10, 2014 8:30:15 PM UTC-8, portertech wrote:

Hi Travis,

Sensu does not use the daemons gem. You probably don’t want to use Ruby’s Logger in the event loop. You can find the Sensu logger docs here https://github.com/sensu/sensu-logger#usagehttp://www.rubydoc.info/github/sensu/sensu-logger/Sensu/Logger Sensu services do the following for setup https://github.com/sensu/sensu/blob/master/lib/sensu/daemon.rb#L46-L49

Sean.

On Mon, Nov 10, 2014 at 8:24 PM, Travis Bear travi...@gmail.com wrote:

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.

Thanks!

-Travis

Have you inspected the argument value?

···

On Tue, Nov 11, 2014 at 11:07 AM, Sean Porter portertech@gmail.com wrote:

Hey Travis,

You can use https://github.com/sensu/sensu-logger/blob/master/lib/sensu/logger.rb#L12

Sean.

On Tue, Nov 11, 2014 at 11:05 AM, Travis Bear travis.bear@gmail.com wrote:

From looking at the sensu-logger source code, I’m not sure it’s possible to have multiple instances of the logger; they all return the same @stream. I tested this out by creating a new sensu-logger in my extension. Unfortunately the new sensu-logger had the same object_id as the existing one, and logged messages to the same file. Are there any working examples of extensions using different loggers than the main sensu server logger which I could look at?

Thanks!

-Travis

On Monday, November 10, 2014 8:54:22 PM UTC-8, portertech wrote:

Sensu::Logger only supports the JSON format. You can have as many instances of the logger as you need. The main instance, used by the Sensu process, is available to every extension, logger() or @logger.

On Nov 10, 2014 8:48 PM, “Travis Bear” travi...@gmail.com wrote:

It’s not obvious that I can control the message format using the sensu-logging gem. (Config options appear to include log_file and log_level only) I need to get the logged messages out of .json format. Is this supported?

Is it okay to have multiple sensu-loggers defined inside a single Sensu server process?

Thanks!

-Travis

On Monday, November 10, 2014 8:30:15 PM UTC-8, portertech wrote:

Hi Travis,

Sensu does not use the daemons gem. You probably don’t want to use Ruby’s Logger in the event loop. You can find the Sensu logger docs here https://github.com/sensu/sensu-logger#usagehttp://www.rubydoc.info/github/sensu/sensu-logger/Sensu/Logger Sensu services do the following for setup https://github.com/sensu/sensu/blob/master/lib/sensu/daemon.rb#L46-L49

Sean.

On Mon, Nov 10, 2014 at 8:24 PM, Travis Bear travi...@gmail.com wrote:

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.

Thanks!

-Travis

Adding debug statements to the stream.rb file, looks like it’s failing on linen 75 of https://github.com/sensu/sensu-logger/blob/master/lib/sensu/logger/stream.rb

STDOUT.reopen(target, “a”)

-Travis

···

On Tuesday, November 11, 2014 11:49:28 AM UTC-8, portertech wrote:

Have you inspected the argument value?

On Nov 11, 2014 11:48 AM, “Travis Bear” travi...@gmail.com wrote:

Hi Sean,

I tried to use that API, but it caused the sensu server to fail to start. Not surprisingly, since the problem was a logging initialization failure, there was nothing in the server log to indicate what went wrong.

I added some debug output to my local copy of /opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-logger-1.0.0/lib/sensu/logger.rb. The line that’s breaking is line 18 of logger.rb.

@stream.reopen(options[:log_file])

It’s not clear why; I’ve verified the value of options[:log_file] exists and is writable by the sensu user, and that the log disk partition is not full.

Thanks!

-Travis

On Tue, Nov 11, 2014 at 11:07 AM, Sean Porter porte...@gmail.com wrote:

Hey Travis,

You can use https://github.com/sensu/sensu-logger/blob/master/lib/sensu/logger.rb#L12

Sean.

On Tue, Nov 11, 2014 at 11:05 AM, Travis Bear travi...@gmail.com wrote:

From looking at the sensu-logger source code, I’m not sure it’s possible to have multiple instances of the logger; they all return the same @stream. I tested this out by creating a new sensu-logger in my extension. Unfortunately the new sensu-logger had the same object_id as the existing one, and logged messages to the same file. Are there any working examples of extensions using different loggers than the main sensu server logger which I could look at?

Thanks!

-Travis

On Monday, November 10, 2014 8:54:22 PM UTC-8, portertech wrote:

Sensu::Logger only supports the JSON format. You can have as many instances of the logger as you need. The main instance, used by the Sensu process, is available to every extension, logger() or @logger.

On Nov 10, 2014 8:48 PM, “Travis Bear” travi...@gmail.com wrote:

It’s not obvious that I can control the message format using the sensu-logging gem. (Config options appear to include log_file and log_level only) I need to get the logged messages out of .json format. Is this supported?

Is it okay to have multiple sensu-loggers defined inside a single Sensu server process?

Thanks!

-Travis

On Monday, November 10, 2014 8:30:15 PM UTC-8, portertech wrote:

Hi Travis,

Sensu does not use the daemons gem. You probably don’t want to use Ruby’s Logger in the event loop. You can find the Sensu logger docs here https://github.com/sensu/sensu-logger#usagehttp://www.rubydoc.info/github/sensu/sensu-logger/Sensu/Logger Sensu services do the following for setup https://github.com/sensu/sensu/blob/master/lib/sensu/daemon.rb#L46-L49

Sean.

On Mon, Nov 10, 2014 at 8:24 PM, Travis Bear travi...@gmail.com wrote:

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.

Thanks!

-Travis