Class: Log4r::GelfOutputter

Inherits:
Outputter
  • Object
show all
Defined in:
lib/log4r-gelf/gelf_outputter.rb

Constant Summary collapse

LEVELS_MAP =
{
  "DEBUG"  => GELF::Levels::DEBUG,
  "INFO"   => GELF::Levels::INFO,
  "WARN"   => GELF::Levels::WARN,
  "ERROR"  => GELF::Levels::ERROR,
  "FATAL"  => GELF::Levels::FATAL,
}

Instance Method Summary collapse

Constructor Details

#initialize(_name, hash = {}) ⇒ GelfOutputter

Returns a new instance of GelfOutputter.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/log4r-gelf/gelf_outputter.rb', line 16

def initialize(_name, hash={})
  super(_name, hash)

  server = hash['gelf_server'] || "127.0.0.1"
  port = (hash['gelf_port'] || 12201).to_i
  max_chunk_size = hash['max_chunk_size'] || 'LAN'
  opts = {}
  opts['host'] = hash['host'] if hash['host']
  opts['facility'] = hash['facility'] if hash['facility']
  opts['level'] = LEVELS_MAP[hash['level']] if hash['level']

  @gdc_key = hash.has_key?('global_context_key') ? hash['global_context_key'] : "gdc"
  @ndc_prefix = hash.has_key?('nested_context_prefix') ? hash['nested_context_prefix'] : "ndc_"
  @mdc_prefix = hash.has_key?('mapped_context_prefix') ? hash['mapped_context_prefix'] : "mdc_"
  
  @notifier = GELF::Notifier.new(server, port, max_chunk_size, opts)
  # Only collect file/line if user turns on trace in log4r config
  @notifier.collect_file_and_line = false
  @notifier.level_mapping = hash['level_mapping'] || :direct
end

Instance Method Details

#format_attribute(value) ⇒ Object



37
38
39
# File 'lib/log4r-gelf/gelf_outputter.rb', line 37

def format_attribute(value)
  value.inspect
end