Class: Steno::Sink::IO
Instance Attribute Summary collapse
-
#max_retries ⇒ Object
readonly
Returns the value of attribute max_retries.
Attributes inherited from Base
Class Method Summary collapse
-
.for_file(path, opts = {}) ⇒ Steno::Sink::IO
Returns a new sink configured to append to the file at path.
Instance Method Summary collapse
- #add_record(record) ⇒ Object
- #flush ⇒ Object
-
#initialize(io, opts = {}) ⇒ IO
constructor
A new instance of IO.
Constructor Details
#initialize(io, opts = {}) ⇒ IO
Returns a new instance of IO.
37 38 39 40 41 42 43 |
# File 'lib/steno/sink/io.rb', line 37 def initialize(io, opts = {}) super(opts[:codec]) @max_retries = opts[:max_retries] || -1 @io_lock = Mutex.new @io = io end |
Instance Attribute Details
#max_retries ⇒ Object (readonly)
Returns the value of attribute max_retries.
29 30 31 |
# File 'lib/steno/sink/io.rb', line 29 def max_retries @max_retries end |
Class Method Details
.for_file(path, opts = {}) ⇒ Steno::Sink::IO
Returns a new sink configured to append to the file at path.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/steno/sink/io.rb', line 17 def for_file(path, opts = {}) autoflush = true autoflush = opts[:autoflush] if opts.include?(:autoflush) io = File.open(path, 'a+') io.sync = autoflush new(io, max_retries: opts[:max_retries]) end |
Instance Method Details
#add_record(record) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/steno/sink/io.rb', line 45 def add_record(record) bytes = @codec.encode_record(record) @io_lock.synchronize do retries = 0 begin @io.write(bytes) rescue IOError => e raise e unless retries < @max_retries retries += 1 retry end end nil end |
#flush ⇒ Object
63 64 65 66 67 |
# File 'lib/steno/sink/io.rb', line 63 def flush @io_lock.synchronize { @io.flush } nil end |