Class: SemanticLogger::Appender::Splunk

Inherits:
Base
  • Object
show all
Defined in:
lib/semantic_logger/appender/splunk.rb

Overview

Note: Not recommended to use the colorized formatter.

Instance Attribute Summary collapse

Attributes inherited from Base

#formatter

Attributes inherited from Base

#filter, #name

Instance Method Summary collapse

Methods inherited from Base

colorized_formatter, #default_formatter, #flush, #level

Methods inherited from Base

#benchmark, default_level, default_level=, #level, #level=, #payload, #pop_tags, #push_tags, #silence, #tagged, #tags, #with_payload

Constructor Details

#initialize(options, level = :error, &block) ⇒ Splunk

Allow the level for this appender to be overwritten

Default: :error


9
10
11
12
13
14
15
16
17
# File 'lib/semantic_logger/appender/splunk.rb', line 9

def initialize(options, level=:error, &block)
  # Parse input options for setting up splunk connection
  parse_options(options)

  reopen

  # Pass on the level and custom formatter if supplied
  super(level, &block)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/semantic_logger/appender/splunk.rb', line 5

def config
  @config
end

#indexObject (readonly)

Returns the value of attribute index.



5
6
7
# File 'lib/semantic_logger/appender/splunk.rb', line 5

def index
  @index
end

#serviceObject (readonly)

Returns the value of attribute service.



5
6
7
# File 'lib/semantic_logger/appender/splunk.rb', line 5

def service
  @service
end

#service_indexObject (readonly)

Returns the value of attribute service_index.



5
6
7
# File 'lib/semantic_logger/appender/splunk.rb', line 5

def service_index
  @service_index
end

Instance Method Details

#log(log) ⇒ Object

Log the message to Splunk



30
31
32
33
34
35
36
# File 'lib/semantic_logger/appender/splunk.rb', line 30

def log(log)
  # Ensure minimum log level is met, and check filter
  return false if (level_index > (log.level_index || 0)) || !include_message?(log)
  # Submit the log message
  @service_index.submit(formatter.call(log))
  true
end

#reopenObject

After forking an active process call #reopen to re-open open the handles to resources



21
22
23
24
25
26
27
# File 'lib/semantic_logger/appender/splunk.rb', line 21

def reopen
  # Connect to splunk. Connect is a synonym for creating a Service by hand and calling login.
  @service       = Splunk::connect(@config)

  # The index we are logging to
  @service_index = @service.indexes[@index]
end