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

#initializeConfig

Returns a new instance of Config.



27
28
29
30
31
# 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]
  @http_body_limit = 2000
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_loggerObject

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.



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

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

#loggerObject

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.



62
63
64
# File 'lib/timber/config.rb', line 62

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)


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

def capture_http_bodies?
  @capture_http_bodies == true
end

#capture_http_body_content_typesObject

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



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

def capture_http_body_content_types
  @capture_http_body_content_types ||= []
end

#http_body_limitObject

Truncates captured HTTP bodies to this specified limit. The default is 2000. If you want to capture more data, you can raise this to a maximum of 5000, or lower this to be more efficient with data.



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

def http_body_limit
  @http_body_limit
end