Class: RedisStreamLogger::LogDevice
- Inherits:
-
Object
- Object
- RedisStreamLogger::LogDevice
- Defined in:
- lib/redis_stream_logger/log_device.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(conn = nil, stream: 'rails-log') ⇒ LogDevice
constructor
Creates a new LogDevice that can be used as a sink for Ruby Logger.
- #reopen(log = nil) ⇒ Object
- #write(msg) ⇒ Object
Constructor Details
#initialize(conn = nil, stream: 'rails-log') ⇒ LogDevice
Creates a new LogDevice that can be used as a sink for Ruby Logger
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/redis_stream_logger/log_device.rb', line 12 def initialize(conn = nil, stream: 'rails-log') @config = Config.new @closed = false # Just in case a whole new config is passed in like in the Railtie new_conf = yield @config if block_given? @config = new_conf if new_conf.is_a?(Config) @config.connection ||= conn @config.stream_name ||= stream raise ArgumentError, 'must provide connection' if @config.connection.nil? @q = Queue.new start end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/redis_stream_logger/log_device.rb', line 5 def config @config end |
Instance Method Details
#close ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/redis_stream_logger/log_device.rb', line 36 def close return if @closed @q.push :exit @ticker.exit @writer.join @config.connection.close @closed = true end |
#reopen(log = nil) ⇒ Object
30 31 32 33 34 |
# File 'lib/redis_stream_logger/log_device.rb', line 30 def reopen(log = nil) close @config.connection._client.connect start end |
#write(msg) ⇒ Object
26 27 28 |
# File 'lib/redis_stream_logger/log_device.rb', line 26 def write(msg) @q.push msg end |