Module: GELF::LoggerCompatibility

Included in:
Logger
Defined in:
lib/gelf/logger.rb

Overview

Methods for compatibility with Ruby Logger.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#formatterObject

Returns the value of attribute formatter



5
6
7
# File 'lib/gelf/logger.rb', line 5

def formatter
  @formatter
end

Instance Method Details

#<<(message) ⇒ Object



51
52
53
# File 'lib/gelf/logger.rb', line 51

def <<(message)
  notify_with_level(GELF::UNKNOWN, 'short_message' => message)
end

#add(level, message = nil, progname = nil, &block) ⇒ Object

Use it like Logger#add… or better not to use at all.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gelf/logger.rb', line 8

def add(level, message = nil, progname = nil, &block)
  progname ||= default_options['facility']

  if message.nil?
    if block_given?
      message = yield
    else
      message = progname
      progname = default_options['facility']
    end
  end

  message_hash = { 'facility' => progname }

  if message.is_a?(Hash)
    # Stringify keys.
    message.each do |k,v|
      message_hash[k.to_s] = message[k]
    end
  else
    message_hash['short_message'] = message
  end

  if message.is_a?(Exception)
    message_hash.merge!(self.class.extract_hash_from_exception(message))
  end

  notify_with_level(level, message_hash)
end