Class: Confium::Audit::FileSink

Inherits:
Sink
  • Object
show all
Defined in:
lib/confium/audit.rb

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

Instance Method Summary collapse

Methods inherited from Sink

#call

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

#pathObject (readonly)

Returns the value of attribute path.



108
109
110
# File 'lib/confium/audit.rb', line 108

def path
  @path
end

Instance Method Details

#closeObject



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