Class: Confium::Audit::FileSink
Overview
Append-only file sink. The path is opened in append mode; each record is written as a single line followed by a newline. Concurrent writes from multiple processes are NOT supported — serialize audit traffic through this sink to a single writer for multi-process deployments.
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(path) ⇒ FileSink
constructor
A new instance of FileSink.
- #write(record) ⇒ Object
Methods inherited from Sink
Constructor Details
#initialize(path) ⇒ FileSink
Returns a new instance of FileSink.
111 112 113 114 115 |
# File 'lib/confium/audit.rb', line 111 def initialize(path) @path = path @io = File.open(path, 'a') @io.sync = true end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
109 110 111 |
# File 'lib/confium/audit.rb', line 109 def path @path end |
Instance Method Details
#close ⇒ Object
121 122 123 |
# File 'lib/confium/audit.rb', line 121 def close @io.close unless @io.closed? end |
#write(record) ⇒ Object
117 118 119 |
# File 'lib/confium/audit.rb', line 117 def write(record) @io.puts(JSON.generate(record)) end |