Module: Wavesync::Logger

Defined in:
lib/wavesync/logger.rb

Class Method Summary collapse

Class Method Details

.capture_invocation(args) ⇒ Object

: (Array args) -> void



18
19
20
# File 'lib/wavesync/logger.rb', line 18

def self.capture_invocation(args)
  @invocation_args = args
end

.configure(library_path) ⇒ Object

: (String? library_path) -> void



7
8
9
10
# File 'lib/wavesync/logger.rb', line 7

def self.configure(library_path)
  @log_path = library_path ? File.join(library_path, 'wavesync.log') : nil
  @invocation_args = nil unless library_path
end

.log_error(error, call_site:, arguments: {}) ⇒ Object

: (Exception error, call_site: String, arguments: Hash[Symbol, untyped]) -> void



34
35
36
37
38
39
40
41
# File 'lib/wavesync/logger.rb', line 34

def self.log_error(error, call_site:, arguments: {})
  path = log_path
  return unless path

  args_str = arguments.map { |key, value| "#{key}: #{value.inspect}" }.join(', ')
  entry = "[#{timestamp}] #{call_site}(#{args_str}) raised #{error.class}: #{error.message}\n"
  File.open(path, 'a') { |file| file.write(entry) }
end

.log_event(message) ⇒ Object

: (String message) -> void



44
45
46
47
48
49
50
# File 'lib/wavesync/logger.rb', line 44

def self.log_event(message)
  path = log_path
  return unless path

  entry = "[#{timestamp}] #{message}\n"
  File.open(path, 'a') { |file| file.write(entry) }
end

.log_invocationObject

: () -> void



23
24
25
26
27
28
29
30
31
# File 'lib/wavesync/logger.rb', line 23

def self.log_invocation
  path = log_path
  return unless path && @invocation_args

  invocation = (['wavesync'] + @invocation_args).join(' ')
  entry = "---\n[#{timestamp}] #{invocation}\n"
  File.open(path, 'a') { |file| file.write(entry) }
  @invocation_args = nil
end

.log_pathObject

: () -> String?



13
14
15
# File 'lib/wavesync/logger.rb', line 13

def self.log_path
  @log_path
end

.log_run_time(seconds) ⇒ Object

: (Float seconds) -> void



53
54
55
56
57
58
59
# File 'lib/wavesync/logger.rb', line 53

def self.log_run_time(seconds)
  path = log_path
  return unless path

  entry = "[#{timestamp}] Run time: #{format_duration(seconds)}\n"
  File.open(path, 'a') { |file| file.write(entry) }
end