Class: SplunkLogger::Client
- Inherits:
-
Object
- Object
- SplunkLogger::Client
- Includes:
- Log
- Defined in:
- lib/splunk_logger/client.rb,
lib/splunk_logger/client/log.rb
Defined Under Namespace
Modules: Log
Constant Summary collapse
- COLLECTOR_PATH =
'/services/collector/event'
Instance Attribute Summary collapse
-
#message_queue ⇒ Object
Returns the value of attribute message_queue.
Instance Method Summary collapse
- #delayed? ⇒ Boolean
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #start ⇒ Object
- #stop ⇒ Object
Methods included from Log
#debug, #error, #info, #log, #warn
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/splunk_logger/client.rb', line 12 def initialize( = {}) token = [:token] url = [:url] verify_ssl = [:verify_ssl].nil? ? true : [:verify_ssl] @default_level = [:default_level].to_s || 'info' @send_interval = [:send_interval].to_i @max_batch_size = ([:max_batch_size] || 100).to_i @max_queue_size = ([:max_queue_size] || 10000).to_i = [] = 0 headers = {'Authorization': "Splunk #{token}", 'Content-Type': 'application/json'} @conn = Faraday.new(url: url, headers: headers) do |faraday| faraday.request :json faraday.response :json, content_type: 'application/json' faraday.adapter Faraday.default_adapter end @conn.ssl.verify = verify_ssl @semaphore = Mutex.new start end |
Instance Attribute Details
#message_queue ⇒ Object
Returns the value of attribute message_queue.
33 34 35 |
# File 'lib/splunk_logger/client.rb', line 33 def end |
Instance Method Details
#delayed? ⇒ Boolean
53 54 55 |
# File 'lib/splunk_logger/client.rb', line 53 def delayed? return @send_interval > 0 end |
#start ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/splunk_logger/client.rb', line 35 def start return unless (@timer.nil? && delayed?) @timer = Thread.new do while true do sleep @send_interval @semaphore.synchronize do send_log end end end end |
#stop ⇒ Object
47 48 49 50 51 |
# File 'lib/splunk_logger/client.rb', line 47 def stop return if @timer.nil? @timer.kill @timer = nil end |