Class: Ask::Agent::Extensions::AuditLog::FileAdapter

Inherits:
Adapter
  • Object
show all
Defined in:
lib/ask/agent/extensions/audit_log.rb

Overview

Built-in adapter: appends JSON lines to a file.

Instance Method Summary collapse

Constructor Details

#initialize(path: "tmp/agent_audit.jsonl") ⇒ FileAdapter

Returns a new instance of FileAdapter.



33
34
35
36
# File 'lib/ask/agent/extensions/audit_log.rb', line 33

def initialize(path: "tmp/agent_audit.jsonl")
  @path = path
  @mutex = Mutex.new
end

Instance Method Details

#write(entry) ⇒ Object



38
39
40
41
42
# File 'lib/ask/agent/extensions/audit_log.rb', line 38

def write(entry)
  @mutex.synchronize do
    File.open(@path, "a") { |f| f.puts(JSON.generate(entry)) }
  end
end