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, SimpleFormatter
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
29 30 31 |
# File 'lib/timber/config.rb', line 29 def (value) @append_metadata = 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.
47 48 49 |
# File 'lib/timber/config.rb', line 47 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.
99 100 101 |
# File 'lib/timber/config.rb', line 99 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.
113 114 115 |
# File 'lib/timber/config.rb', line 113 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.
145 146 147 148 149 150 151 |
# File 'lib/timber/config.rb', line 145 def logger if @logger.is_a?(Proc) @logger.call() else @logger ||= Logger.new(STDOUT) end end |
Instance Method Details
#append_metadata? ⇒ Boolean
This determines if the log messages should have metadata appended. Ex:
log message @metadata {...}
By default, this is turned on for production and staging environments only. Other environment should set this setting explicitly.
128 129 130 131 132 133 134 |
# File 'lib/timber/config.rb', line 128 def if defined?(@append_metadata) return @append_metadata == true end production? || staging? end |
#debug_to_file(file_path) ⇒ Object
A convenience method for writing debug messages to a file.
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/timber/config.rb', line 57 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 = SimpleFormatter.new self.debug_logger = file_logger end |
#debug_to_stdout ⇒ Object
A convenience method for writing debug messages to a file.
75 76 77 78 79 |
# File 'lib/timber/config.rb', line 75 def debug_to_stdout stdout_logger = ::Logger.new(STDOUT) stdout_logger.formatter = SimpleFormatter.new 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.
89 90 91 |
# File 'lib/timber/config.rb', line 89 def environment @environment ||= ENV["RACK_ENV"] || ENV["RAILS_ENV"] || "development" end |