Class: Timber::Config

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

Overview

Interface for setting and reading Timber configuration.

For Rails apps this is installed into ‘config.timber`. See examples below.

Examples:

Rails example

config.timber. = false

Everything else

config = Timber::Config.instance
config.append_metdata = false

Defined Under Namespace

Classes: NoLoggerError

Constant Summary collapse

PRODUCTION_NAME =
"production".freeze
STAGING_NAME =
"staging".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#append_metadata=(value) ⇒ Object (writeonly)

Sets the attribute append_metadata

Parameters:

  • value

    the value to set the attribute append_metadata to.



21
22
23
# File 'lib/timber/config.rb', line 21

def append_metadata=(value)
  @append_metadata = 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.

Examples:

Rails

config.timber.debug_logger = ::Logger.new(STDOUT)

Everything else

Timber::Config.instance.debug_logger = ::Logger.new(STDOUT)


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

def debug_logger
  @debug_logger
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.

Examples:

Rails

config.timber.http_body_limit = 500

Everything else

Timber::Config.instance.http_body_limit = 500


58
59
60
# File 'lib/timber/config.rb', line 58

def http_body_limit
  @http_body_limit
end

#loggerObject

This is the logger Timber writes to. All of the Timber integrations write to this logger. It should be set to your global logger to keep the logging destination consitent.

For Rails this is set automatically to ‘Rails.logger`.

Examples:

Rails

Rails.logger = Timber::Logger.new(STDOUT)
config.timber.logger = Rails.logger

Everything else

Timber::Config.instance.logger = Timber::Logger.new(STDOUT)


90
91
92
# File 'lib/timber/config.rb', line 90

def logger
  @logger || Logger.new(STDOUT)
end

Instance Method Details

#append_metadata?Boolean

Should the logger append the Timber metadata. This is automatically turned on for production and staging environments. Other environments should be set manually. If set to ‘true` log messages will look like:

log message @metadata {...}

Examples:

Rails

config.timber. = false

Everything else

Timber::Config.instance. = false

Returns:

  • (Boolean)


72
73
74
75
76
77
78
# File 'lib/timber/config.rb', line 72

def append_metadata?
  if defined?(@append_metadata)
    return @append_metadata == true
  end

  production? || staging?
end

#environmentObject

The environment your app is running in. Defaults to ‘RACK_ENV` and `RAILS_ENV`.

Examples:

Rails

config.timber.environment = "staging"

Everything else

Timber::Config.instance.environment = "staging"


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

def environment
  @environment ||= ENV["RACK_ENV"] || ENV["RAILS_ENV"] || "development"
end