Class: Vx::Lib::Logger::LogstashDevice
- Inherits:
-
Object
- Object
- Vx::Lib::Logger::LogstashDevice
- Defined in:
- lib/vx/lib/logger/logstash_device.rb
Instance Method Summary collapse
- #close ⇒ Object
- #connected? ⇒ Boolean
- #enabled? ⇒ Boolean
- #flush ⇒ Object
-
#initialize ⇒ LogstashDevice
constructor
A new instance of LogstashDevice.
- #uri ⇒ Object
- #write(message) ⇒ Object
Constructor Details
#initialize ⇒ LogstashDevice
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
#close ⇒ Object
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
24 25 26 |
# File 'lib/vx/lib/logger/logstash_device.rb', line 24 def connected? !!@io end |
#enabled? ⇒ Boolean
20 21 22 |
# File 'lib/vx/lib/logger/logstash_device.rb', line 20 def enabled? !!uri end |
#flush ⇒ Object
46 47 48 |
# File 'lib/vx/lib/logger/logstash_device.rb', line 46 def flush @io && @io.flush end |
#uri ⇒ Object
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() if enabled? @mutex.synchronize do with_connection do @io.write end end end end |