Class: Timber::Config
- Inherits:
-
Object
- Object
- Timber::Config
- 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.
Defined Under Namespace
Classes: NoLoggerError
Constant Summary collapse
- PRODUCTION_NAME =
"production".freeze
- STAGING_NAME =
"staging".freeze
Instance Attribute Summary collapse
-
#append_metadata ⇒ Object
writeonly
Sets the attribute append_metadata.
-
#debug_logger ⇒ Object
This is useful for debugging.
-
#header_filters ⇒ Object
This is a list of header keys that should be filtered.
-
#http_body_limit ⇒ Object
Truncates captured HTTP bodies to this specified limit.
-
#logger ⇒ Object
This is the main logger Timber writes to.
Instance Method Summary collapse
-
#append_metadata? ⇒ Boolean
This determines if the log messages should have metadata appended.
-
#debug_to_file(file_path) ⇒ Object
A convenience method for writing debug messages to a file.
-
#debug_to_stdout ⇒ Object
A convenience method for writing debug messages to a file.
-
#environment ⇒ Object
The environment your app is running in.
Instance Attribute Details
#append_metadata=(value) ⇒ Object (writeonly)
Sets the attribute append_metadata
21 22 23 |
# File 'lib/timber/config.rb', line 21 def (value) = value end |
#debug_logger ⇒ Object
This is useful for debugging. This Sets a debug_logger to view internal Timber library log messages. The default is ‘nil`. Meaning log to nothing.
See ‘debug_to_file` and `debug_to_stdout` for convenience methods that handle creating and setting the logger.
39 40 41 |
# File 'lib/timber/config.rb', line 39 def debug_logger @debug_logger end |
#header_filters ⇒ Object
This is a list of header keys that should be filtered. Note, all headers are normalized to down-case. So please only pass down-cased headers.
89 90 91 |
# File 'lib/timber/config.rb', line 89 def header_filters @header_filters end |
#http_body_limit ⇒ Object
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. `2000` characters should give you a good idea of the body content. If you need to raise to `5000` you’re only constraint is network throughput.
103 104 105 |
# File 'lib/timber/config.rb', line 103 def http_body_limit @http_body_limit end |
#logger ⇒ Object
This is the main logger Timber writes to. All of the Timber integrations write to this logger instance. It should be set to your global logger. For Rails, this is set automatically to ‘Rails.logger`, you should not have to set this.
135 136 137 |
# File 'lib/timber/config.rb', line 135 def logger @logger || Logger.new(STDOUT) end |
Instance Method Details
#append_metadata? ⇒ Boolean
This determines if the log messages should have metadata appended. Ex:
log {...}
By default, this is turned on for production and staging environments only. Other environment should set this setting explicitly.
118 119 120 121 122 123 124 |
# File 'lib/timber/config.rb', line 118 def if defined?() return == true end production? || staging? end |
#debug_to_file(file_path) ⇒ Object
A convenience method for writing debug messages to a file.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/timber/config.rb', line 49 def debug_to_file(file_path) unless File.exist? File.dirname path FileUtils.mkdir_p File.dirname path end file = File.open file_path, "a" file.binmode file.sync = config.autoflush_log file_logger = ::Logger.new(file) self.debug_logger = file_logger end |
#debug_to_stdout ⇒ Object
A convenience method for writing debug messages to a file.
66 67 68 69 |
# File 'lib/timber/config.rb', line 66 def debug_to_stdout stdout_logger = ::Logger.new(STDOUT) self.debug_logger = stdout_logger end |
#environment ⇒ Object
The environment your app is running in. Defaults to ‘RACK_ENV` and `RAILS_ENV`. It should be rare that you have to set this. If the aforementioned env vars are not set please do.
79 80 81 |
# File 'lib/timber/config.rb', line 79 def environment @environment ||= ENV["RACK_ENV"] || ENV["RAILS_ENV"] || "development" end |