Class: HTTPigeon::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/httpigeon/logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_type: nil, log_filters: nil) ⇒ Logger

Returns a new instance of Logger.



8
9
10
11
# File 'lib/httpigeon/logger.rb', line 8

def initialize(event_type: nil, log_filters: nil)
  @event_type = event_type || HTTPigeon.default_event_type
  @log_redactor = HTTPigeon.log_redactor || HTTPigeon::LogRedactor.new(log_filters: HTTPigeon.default_filter_keys | log_filters.to_a)
end

Instance Attribute Details

#end_timeObject (readonly)

Returns the value of attribute end_time.



6
7
8
# File 'lib/httpigeon/logger.rb', line 6

def end_time
  @end_time
end

#event_typeObject (readonly)

Returns the value of attribute event_type.



6
7
8
# File 'lib/httpigeon/logger.rb', line 6

def event_type
  @event_type
end

#log_redactorObject (readonly)

Returns the value of attribute log_redactor.



6
7
8
# File 'lib/httpigeon/logger.rb', line 6

def log_redactor
  @log_redactor
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



6
7
8
# File 'lib/httpigeon/logger.rb', line 6

def start_time
  @start_time
end

Instance Method Details

#log(faraday_env, data = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/httpigeon/logger.rb', line 13

def log(faraday_env, data = {})
  base_log_data = { event_type: event_type }
  log_data = build_log_data(faraday_env, data).merge(base_log_data)

  HTTPigeon.event_logger.nil? ? log_to_stdout(log_data) : HTTPigeon.event_logger.log(log_data)
rescue StandardError => e
  HTTPigeon.exception_notifier.notify_exception(e) if HTTPigeon.notify_all_exceptions
  raise e if ['development', 'test'].include?(ENV['RAILS_ENV'].to_s)
end

#on_request_finishObject



27
28
29
# File 'lib/httpigeon/logger.rb', line 27

def on_request_finish
  @end_time = Time.current
end

#on_request_startObject



23
24
25
# File 'lib/httpigeon/logger.rb', line 23

def on_request_start
  @start_time = Time.current
end