Class: Thoth::Logger

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(outputs, options = {}) ⇒ Logger

Returns a new instance of Logger.



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

def initialize(outputs, options={})
  @outputs = [outputs].flatten
  @timestamp_format = options.fetch(:timestamp_format, "%d/%b/%Y:%H:%M:%S %z")
  @timestamp_key = options.fetch(:timestamp_key, :time)
end

Instance Attribute Details

#outputsObject (readonly)

Returns the value of attribute outputs.



4
5
6
# File 'lib/thoth/logger.rb', line 4

def outputs
  @outputs
end

#timestamp_formatObject (readonly)

Returns the value of attribute timestamp_format.



4
5
6
# File 'lib/thoth/logger.rb', line 4

def timestamp_format
  @timestamp_format
end

#timestamp_keyObject (readonly)

Returns the value of attribute timestamp_key.



4
5
6
# File 'lib/thoth/logger.rb', line 4

def timestamp_key
  @timestamp_key
end

Instance Method Details

#log(event_name, details = {}, context = {}) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/thoth/logger.rb', line 17

def log(event_name, details={}, context={})
  event_data = marshal_event(event_name, details, context)

  outputs.each do |output|
    output.write(event_data)
  end
end

#param_filterObject

lazy load this since this class is initialized before rails’ filter_parameters is set



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

def param_filter
  @param_filter ||= ::ActionDispatch::Http::ParameterFilter.new(::Rails.application.config.filter_parameters)
end