Class: Vx::Lib::Logger::LogstashDevice

Inherits:
Object
  • Object
show all
Defined in:
lib/vx/lib/logger/logstash_device.rb

Instance Method Summary collapse

Constructor Details

#initializeLogstashDevice

Returns a new instance of LogstashDevice.



9
10
11
# File 'lib/vx/lib/logger/logstash_device.rb', line 9

def initialize
  @mutex = Mutex.new
end

Instance Method Details

#closeObject



28
29
30
31
32
33
34
# File 'lib/vx/lib/logger/logstash_device.rb', line 28

def close
  @io && @io.close
rescue Exception => e
  warn "#{self.class} - #{e.class} - #{e.message}"
ensure
  @io = nil
end

#connected?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/vx/lib/logger/logstash_device.rb', line 24

def connected?
  !!@io
end

#enabled?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/vx/lib/logger/logstash_device.rb', line 20

def enabled?
  !!uri
end

#flushObject



46
47
48
# File 'lib/vx/lib/logger/logstash_device.rb', line 46

def flush
  @io && @io.flush
end

#uriObject



13
14
15
16
17
18
# File 'lib/vx/lib/logger/logstash_device.rb', line 13

def uri
  @uri ||= begin
    h = ENV['LOGSTASH_HOST']
    URI("logstash://#{h}") if h
  end
end

#write(message) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/vx/lib/logger/logstash_device.rb', line 36

def write(message)
  if enabled?
    @mutex.synchronize do
      with_connection do
        @io.write message
      end
    end
  end
end