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
- DEFAULT_HTTP_BODY_LIMIT =
2048.freeze
- 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=
144 145 146 |
# File 'lib/timber/config.rb', line 144 def http_body_limit @http_body_limit end |
Instance Method Details
#debug_logger ⇒ Object
Accessor method for #debug_logger=.
70 71 72 |
# File 'lib/timber/config.rb', line 70 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.
65 66 67 |
# File 'lib/timber/config.rb', line 65 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.
80 81 82 83 84 85 86 |
# File 'lib/timber/config.rb', line 80 def debug_to_file!(file_path) FileUtils.mkdir_p( File.dirname(file_path) ) file = File.open(file_path, "ab") 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.
94 95 96 97 98 |
# File 'lib/timber/config.rb', line 94 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=
111 112 113 |
# File 'lib/timber/config.rb', line 111 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.
106 107 108 |
# File 'lib/timber/config.rb', line 106 def environment=(value) @environment = value end |
#http_header_filters ⇒ Object
Accessor method for #http_header_filters=
126 127 128 |
# File 'lib/timber/config.rb', line 126 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.
121 122 123 |
# File 'lib/timber/config.rb', line 121 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.
151 152 153 |
# File 'lib/timber/config.rb', line 151 def integrations Integrations end |
#logger ⇒ Object
Accessor method for #logger=.
208 209 210 211 212 213 214 |
# File 'lib/timber/config.rb', line 208 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.
203 204 205 |
# File 'lib/timber/config.rb', line 203 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.
189 190 191 192 193 194 |
# File 'lib/timber/config.rb', line 189 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 |