Class: Logatron::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/logatron/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/logatron/configuration.rb', line 29

def initialize
  @logger = Logger.new(STDOUT)
  @app_id = 'N/A'
  @transformer = proc { |x| x.to_json }
  @host = `hostname`.chomp
  @level = INFO
  level_threshold = SEVERITY_MAP[@level]
  levels = Logatron::SEVERITY_MAP.keys
  @loggable_levels = levels.select { |level| SEVERITY_MAP[level] >= level_threshold }
  @backtrace_cleaner = Logatron::BacktraceCleaner.new
  @error_formatter = Logatron::ErrorFormatter.new
  @custom_rails_request_fields = []
end

Instance Attribute Details

#app_idObject

Returns the value of attribute app_id.



26
27
28
# File 'lib/logatron/configuration.rb', line 26

def app_id
  @app_id
end

#backtrace_cleanerObject (readonly)

Returns the value of attribute backtrace_cleaner.



27
28
29
# File 'lib/logatron/configuration.rb', line 27

def backtrace_cleaner
  @backtrace_cleaner
end

#base_controller_classObject

Returns the value of attribute base_controller_class.



26
27
28
# File 'lib/logatron/configuration.rb', line 26

def base_controller_class
  @base_controller_class
end

#custom_rails_request_fieldsObject (readonly)

Returns the value of attribute custom_rails_request_fields.



27
28
29
# File 'lib/logatron/configuration.rb', line 27

def custom_rails_request_fields
  @custom_rails_request_fields
end

#error_formatterObject

Returns the value of attribute error_formatter.



26
27
28
# File 'lib/logatron/configuration.rb', line 26

def error_formatter
  @error_formatter
end

#hostObject

Returns the value of attribute host.



26
27
28
# File 'lib/logatron/configuration.rb', line 26

def host
  @host
end

#levelObject

Returns the value of attribute level.



26
27
28
# File 'lib/logatron/configuration.rb', line 26

def level
  @level
end

#loggable_levelsObject (readonly)

Returns the value of attribute loggable_levels.



27
28
29
# File 'lib/logatron/configuration.rb', line 27

def loggable_levels
  @loggable_levels
end

#loggerObject

Returns the value of attribute logger.



26
27
28
# File 'lib/logatron/configuration.rb', line 26

def logger
  @logger
end

#transformerObject

Returns the value of attribute transformer.



26
27
28
# File 'lib/logatron/configuration.rb', line 26

def transformer
  @transformer
end

Instance Method Details

#add_rails_request_field(name) {|ActionDispatch::Request| ... } ⇒ Object

Add custom fields to the request log line that is produced for every rails request served. This will affect all rails requests for the project.

Examples:

config.add_rails_request_field(:user_agent) { |req| req.user_agent }

Parameters:

  • name (Symbol)

    the display name for the value in the request log line

Yields:

  • (ActionDispatch::Request)

    block for determining the value to display in the request log line. Takes an optional rails request object for the current action as a parameter and returns the string value to put in the request log line.



61
62
63
# File 'lib/logatron/configuration.rb', line 61

def add_rails_request_field(name, &value_block)
  @custom_rails_request_fields.push(name: name, value_block: value_block)
end