Class: Timber::Config
- Inherits:
-
Object
- Object
- Timber::Config
- Includes:
- Singleton
- Defined in:
- lib/timber/config.rb,
lib/timber/config/integrations.rb,
lib/timber/config/integrations/rack.rb
Overview
Singleton class for reading and setting Timber configuration.
For Rails apps, this is installed into ‘config.timber`. See examples below.
Defined Under Namespace
Modules: Integrations
Constant Summary collapse
- DEVELOPMENT_NAME =
"development".freeze
- PRODUCTION_NAME =
"production".freeze
- STAGING_NAME =
"staging".freeze
- TEST_NAME =
"test".freeze
Instance Attribute Summary collapse
-
#http_body_limit ⇒ Object
Accessor method for #http_body_limit=.
Instance Method Summary collapse
-
#debug_logger ⇒ Object
Accessor method for #debug_logger=.
-
#debug_logger=(value) ⇒ Object
This is useful for debugging.
-
#debug_to_file!(file_path) ⇒ Object
A convenience method for writing internal Timber debug messages to a file.
-
#debug_to_stdout! ⇒ Object
A convenience method for writing internal Timber debug messages to STDOUT.
-
#environment ⇒ Object
Accessor method for #environment=.
-
#environment=(value) ⇒ Object
The environment your app is running in.
-
#http_header_filters ⇒ Object
Accessor method for #http_header_filters=.
-
#http_header_filters=(value) ⇒ Object
This is a list of header keys that should be filtered.
-
#integrations ⇒ Object
Convenience method for accessing the various ‘Timber::Integrations::*` class settings.
-
#logger ⇒ Object
Accessor method for #logger=.
-
#logger=(value) ⇒ Object
This is the main logger Timber writes to.
-
#logrageify! ⇒ Object
A convenience method that automatically sets Timber’s configuration to closely match the behavior of the ruby lograge library.
Instance Attribute Details
#http_body_limit ⇒ Object
Accessor method for #http_body_limit=
147 148 149 |
# File 'lib/timber/config.rb', line 147 def http_body_limit @http_body_limit end |
Instance Method Details
#debug_logger ⇒ Object
Accessor method for #debug_logger=.
69 70 71 |
# File 'lib/timber/config.rb', line 69 def debug_logger @debug_logger end |
#debug_logger=(value) ⇒ 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.
64 65 66 |
# File 'lib/timber/config.rb', line 64 def debug_logger=(value) @debug_logger = value end |
#debug_to_file!(file_path) ⇒ Object
A convenience method for writing internal Timber debug messages to a file.
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/timber/config.rb', line 79 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) file_logger.formatter = SimpleLogFormatter.new self.debug_logger = file_logger end |
#debug_to_stdout! ⇒ Object
A convenience method for writing internal Timber debug messages to STDOUT.
97 98 99 100 101 |
# File 'lib/timber/config.rb', line 97 def debug_to_stdout! stdout_logger = ::Logger.new(STDOUT) stdout_logger.formatter = SimpleLogFormatter.new self.debug_logger = stdout_logger end |
#environment ⇒ Object
Accessor method for #environment=
114 115 116 |
# File 'lib/timber/config.rb', line 114 def environment @environment ||= ENV["RACK_ENV"] || ENV["RAILS_ENV"] || "development" end |
#environment=(value) ⇒ 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.
109 110 111 |
# File 'lib/timber/config.rb', line 109 def environment=(value) @environment = value end |
#http_header_filters ⇒ Object
Accessor method for #http_header_filters=
129 130 131 |
# File 'lib/timber/config.rb', line 129 def http_header_filters @http_header_filters ||= [] end |
#http_header_filters=(value) ⇒ 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.
124 125 126 |
# File 'lib/timber/config.rb', line 124 def http_header_filters=(value) @http_header_filters = value end |
#integrations ⇒ Object
Convenience method for accessing the various ‘Timber::Integrations::*` class settings. These provides settings for enabling, disabled, and silencing integrations. See Integrations for a full list of available methods.
154 155 156 |
# File 'lib/timber/config.rb', line 154 def integrations Integrations end |
#logger ⇒ Object
Accessor method for #logger=.
211 212 213 214 215 216 217 |
# File 'lib/timber/config.rb', line 211 def logger if @logger.is_a?(Proc) @logger.call() else @logger ||= Logger.new(STDOUT) end end |
#logger=(value) ⇒ 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.
206 207 208 |
# File 'lib/timber/config.rb', line 206 def logger=(value) @logger = value end |
#logrageify! ⇒ Object
A convenience method that automatically sets Timber’s configuration to closely match the behavior of the ruby lograge library. This makes it easier when transitioning from lograge.
It turns this:
Started GET "/" for 127.0.0.1 at 2012-03-10 14:28:14 +0100
Processing by HomeController#index as HTML
Rendered text template within layouts/application (0.0ms)
Rendered layouts/_assets.html.erb (2.0ms)
Rendered layouts/_top.html.erb (2.6ms)
Rendered layouts/_about.html.erb (0.3ms)
Rendered layouts/_google_analytics.html.erb (0.4ms)
Completed 200 OK in 79ms (Views: 78.8ms | ActiveRecord: 0.0ms)
Into this:
Get "/" sent 200 OK in 79ms @metadata {...}
In other words it:
-
Silences ActiveRecord SQL query logs.
-
Silences ActiveView template rendering logs.
-
Silences ActionController controller call logs.
-
Collapses HTTP request and response logs into a single event.
Notice also that is is not exactly like lograge. This is intentional. Lograge has a number of downsides:
-
The attribute names (‘method`, `format`, `status`, `db`, etc) are too generalized and vague. This makes it very likely that it will clash with other structured data you’re logging.
-
It doesn’t support context making it near impossible to view in-app logs generated for the same request.
192 193 194 195 196 197 |
# File 'lib/timber/config.rb', line 192 def logrageify! integrations.action_controller.silence = true integrations.action_view.silence = true integrations.active_record.silence = true integrations.rack.http_events.collapse_into_single_event = true end |