Class: Kitsune::Kit::RunLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/kitsune/kit/run_logger.rb

Constant Summary collapse

MAX_FILES =
20

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root:, run_id:, secret_filter: SecretFilter.new, clock: Clock.new) ⇒ RunLogger

Returns a new instance of RunLogger.



14
15
16
17
18
19
20
21
22
# File 'lib/kitsune/kit/run_logger.rb', line 14

def initialize(root:, run_id:, secret_filter: SecretFilter.new, clock: Clock.new)
  directory = Pathname(root).expand_path.join(".kitsune/logs")
  FileUtils.mkdir_p(directory, mode: 0o700)
  @path = directory.join("#{clock.now.strftime('%Y%m%dT%H%M%S')}-#{run_id}.jsonl")
  @secret_filter = secret_filter
  FileUtils.touch(@path)
  File.chmod(0o600, @path)
  rotate(directory)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



12
13
14
# File 'lib/kitsune/kit/run_logger.rb', line 12

def path
  @path
end

Instance Method Details

#handle(event) ⇒ Object



24
25
26
27
28
# File 'lib/kitsune/kit/run_logger.rb', line 24

def handle(event)
  File.open(path, "a", 0o600) do |file|
    file.puts(JSON.generate(@secret_filter.filter(event.to_h)))
  end
end