class Logtail::Config
Singleton class for reading and setting Logtail
configuration.
For Rails apps, this is installed into `config.logtail`. See examples below.
@example Rails example
config.logtail.append_metadata = false
@example Everything else
config = Logtail::Config.instance config.append_metdata = false
Constants
- DEVELOPMENT_NAME
- PRODUCTION_NAME
- STAGING_NAME
- TEST_NAME
Attributes
Public Instance Methods
Convenience method for logging debug statements to the debug logger set in this class. @private
# File lib/logtail/config.rb, line 38 def debug(&block) debug_logger = Config.instance.debug_logger if debug_logger message = yield debug_logger.debug(message) end true end
Accessor method for {#debug_logger=}.
# File lib/logtail/config.rb, line 62 def debug_logger @debug_logger end
This is useful for debugging. This Sets a debug_logger
to view internal Logtail
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.
@example Rails
config.logtail.debug_logger = ::Logger.new(STDOUT)
@example Everything else
Logtail::Config.instance.debug_logger = ::Logger.new(STDOUT)
# File lib/logtail/config.rb, line 57 def debug_logger=(value) @debug_logger = value end
A convenience method for writing internal Logtail
debug messages to a file.
@example Rails
config.Logtail.debug_to_file!("#{Rails.root}/log/logtail.log")
@example Everything else
Logtail::Config.instance.debug_to_file!("log/logtail.log")
# File lib/logtail/config.rb, line 72 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
A convenience method for writing internal Logtail
debug messages to STDOUT.
@example Rails
config.logtail.debug_to_stdout!
@example Everything else
Logtail::Config.instance.debug_to_stdout!
# File lib/logtail/config.rb, line 86 def debug_to_stdout! stdout_logger = ::Logger.new(STDOUT) stdout_logger.formatter = SimpleLogFormatter.new self.debug_logger = stdout_logger end
@private
# File lib/logtail/config.rb, line 135 def development? environment == DEVELOPMENT_NAME end
Accessor method for {#environment=}
# File lib/logtail/config.rb, line 103 def environment @environment ||= ENV["RACK_ENV"] || ENV["RAILS_ENV"] || "development" end
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.
@example If you do not set `RACK_ENV` or `RAILS_ENV`
Logtail::Config.instance.environment = "staging"
# File lib/logtail/config.rb, line 98 def environment=(value) @environment = value end
Convenience method for accessing the various `Logtail::Integrations::*` class settings. These provides settings for enabling, disabled, and silencing integrations. See {Integrations} for a full list of available methods.
# File lib/logtail/config.rb, line 110 def integrations Integrations end
Accessor method for {#logger=}.
# File lib/logtail/config.rb, line 126 def logger if @logger.is_a?(Proc) @logger.call() else @logger ||= Logger.new(STDOUT) end end
This is the main logger Logtail
writes to. All of the Logtail
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.
@example Non-rails frameworks
my_global_logger = Logtail::Logger.new(STDOUT) Logtail::Config.instance.logger = my_global_logger
# File lib/logtail/config.rb, line 121 def logger=(value) @logger = value end
@private
# File lib/logtail/config.rb, line 145 def production? environment == PRODUCTION_NAME end
@private
# File lib/logtail/config.rb, line 150 def staging? environment == STAGING_NAME end
@private
# File lib/logtail/config.rb, line 140 def test? environment == TEST_NAME end