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



59
60
61
# File 'lib/gelf/logger.rb', line 59

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

#add(level, *args) ⇒ Object

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

Raises:

  • (ArgumentError)


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
37
38
39
40
41
42
43
# File 'lib/gelf/logger.rb', line 12

def add(level, *args)
  raise ArgumentError.new('Wrong arguments.') unless (0..2).include?(args.count)

  # Ruby Logger's author is a maniac.
  message, progname = if args.count == 2
                        [args[0], args[1]]
                      elsif args.count == 0
                        [yield, default_options['facility']]
                      elsif block_given?
                        [yield, args[0]]
                      else
                        [args[0], default_options['facility']]
                      end

  if message.is_a?(Hash)
    # Stringify keys.
    hash = {}
    message.each do |k,v|
      hash[k.to_s] = message[k]
    end

    hash['facility'] = progname
  else
    hash = {'short_message' => message, 'facility' => progname}
  end

  hash['facility'] = default_options['facility'] unless progname

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

  notify_with_level(level, hash)
end

#closeObject

Does nothing.



8
9
# File 'lib/gelf/logger.rb', line 8

def close
end