Class: Timber::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/timber/config.rb

Overview

Interface for settings and reading Timber configuration.

You can override any configuration supplied here by simply setting it:

# Rails
config.timber.api_key = "my api key"

# Everything else
Timber::Config.instance.api_key = "my api key"

If a value is not explicity set, the environment is checked for it's associated environment variable. If that is not set, a reasonable default will be chosen. Each method documents this.

Defined Under Namespace

Classes: NoLoggerError

Constant Summary collapse

FORM_URL_ENCODED_CONTENT_TYPE =
"application/x-www-form-urlencoded".freeze
JSON_CONTENT_TYPE =
"application/json".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Config

Returns a new instance of Config.



27
28
29
30
# File 'lib/timber/config.rb', line 27

def initialize
  @capture_http_bodies = true
  @capture_http_body_content_types = [FORM_URL_ENCODED_CONTENT_TYPE, JSON_CONTENT_TYPE]
end

Instance Attribute Details

#capture_http_bodies=(value) ⇒ Object (writeonly)

Sets the attribute capture_http_bodies

Parameters:

  • value —

    the value to set the attribute capture_http_bodies to.



25
26
27
# File 'lib/timber/config.rb', line 25

def capture_http_bodies=(value)
  @capture_http_bodies = value
end

#debug_logger ⇒ Object

Set a debug_logger to view internal Timber library log message. Useful for debugging. Defaults to nil. If set, debug messages will be written to this logger.



46
47
48
# File 'lib/timber/config.rb', line 46

def debug_logger
  @debug_logger
end

#log_formatter=(value) ⇒ Object (writeonly)

Sets the attribute log_formatter

Parameters:

  • value —

    the value to set the attribute log_formatter to.



25
26
27
# File 'lib/timber/config.rb', line 25

def log_formatter=(value)
  @log_formatter = value
end

#logger ⇒ Object

This is the logger Timber writes to. It should be set to your global logger to keep the logging destination consitent. Please see delegate_logger_to to delegate this call to another method. This is set to Rails.logger for rails.



55
56
57
# File 'lib/timber/config.rb', line 55

def logger
  @logger || raise(NoLoggerError.new)
end

Instance Method Details

#capture_http_bodies? ⇒ Boolean

Enables and disables the capturing of HTTP bodies in Events::HTTPServerRequest, HTTPClientRequest, and HTTPClientRespone.

Returns:

  • (Boolean)


34
35
36
# File 'lib/timber/config.rb', line 34

def capture_http_bodies?
  @capture_http_bodies == true
end

#capture_http_body_content_types ⇒ Object

Limits HTTP body capturing to the listed content types. This must be an array.



39
40
41
# File 'lib/timber/config.rb', line 39

def capture_http_body_content_types
  @capture_http_body_content_types ||= []
end