Module: Sensu::Logger

Defined in:
lib/sensu/logger.rb,
lib/sensu/logger/stream.rb,
lib/sensu/logger/constants.rb

Defined Under Namespace

Classes: Stream

Constant Summary collapse

LEVELS =
[:debug, :info, :warn, :error, :fatal]

Class Method Summary collapse

Class Method Details

.get(options = {}) ⇒ Stream

Retrieve the current log stream or set one up if there isn't one. Note: We may need to add a mutex for thread safety.

Parameters:

  • options (Hash) (defaults to: {})

    to pass to setup().

Returns:

  • (Stream)

    instance of a log stream.



28
29
30
# File 'lib/sensu/logger.rb', line 28

def get(options={})
  @stream || setup(options)
end

.setup(options = {}) ⇒ Stream

Setup a log stream.

Parameters:

  • options (Hash) (defaults to: {})

    to create the log stream with.

Options Hash (options):

  • :log_level (String)

    to use.

  • :log_file (String)

    to use.

Returns:

  • (Stream)

    instance of a log stream.



12
13
14
15
16
17
18
19
20
21
# File 'lib/sensu/logger.rb', line 12

def setup(options={})
  @stream = Stream.new
  if options[:log_level]
    @stream.level = options[:log_level]
  end
  if options[:log_file]
    @stream.reopen(options[:log_file])
  end
  @stream
end