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.
39 40 41 42 43 44 45 |
# File 'lib/steno/sink/io.rb', line 39 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.
31 32 33 |
# File 'lib/steno/sink/io.rb', line 31 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 27 28 |
# File 'lib/steno/sink/io.rb', line 17 def for_file(path, opts = {}) autoflush = true if opts.include?(:autoflush) autoflush = opts[:autoflush] end io = File.open(path, "a+") io.sync = autoflush new(io, :max_retries => opts[:max_retries]) end |
Instance Method Details
#add_record(record) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/steno/sink/io.rb', line 47 def add_record(record) bytes = @codec.encode_record(record) @io_lock.synchronize do retries = 0 begin @io.write(bytes) rescue IOError => e if retries < @max_retries retries += 1 retry else raise e end end end nil end |
#flush ⇒ Object
67 68 69 70 71 |
# File 'lib/steno/sink/io.rb', line 67 def flush @io_lock.synchronize { @io.flush } nil end |