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.
110 111 112 113 114 |
# File 'lib/confium/audit.rb', line 110 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.
108 109 110 |
# File 'lib/confium/audit.rb', line 108 def path @path end |
Instance Method Details
#close ⇒ Object
120 121 122 |
# File 'lib/confium/audit.rb', line 120 def close @io.close unless @io.closed? end |
#write(record) ⇒ Object
116 117 118 |
# File 'lib/confium/audit.rb', line 116 def write(record) @io.puts(JSON.generate(record)) end |