class Binnacle::Configuration
Constants
- DEFAULT_BACKTRACE_FILTERS
- DEFAULT_IGNORED_EXCEPTIONS
- DEFAULT_PORT
Attributes
An approved publisher API key for the App (BINNACLE_API_KEY)
The API secret for the given API key (BINNACLE_API_SECRET)
Whether to log asynchronoushly via the Ruby logger
Whether to make the requests over HTTPS, default is HTTPS
The Binnacle
Endpoint (BINNACLE_ENDPOINT) single IP or Array of IPs
The application error Binnacle
Channel (BINNACLE_APP_ERR_CHANNEL)
Array of Events to skip, e.g. ['home#index', 'webhooks#test']
Whether to skip reporting exceptions where the headers is set to 'pass'. In Rails typically it means route was not found (404 error).
Exceptions that do not get reported to Binnacle
(BINNACLE_IGNORED_EXCEPTIONS)
Whether to redirect rails logging to Binnacle
(BINNACLE_RAILS_LOG)
The application logger Binnacle
Channel (BINNACLE_APP_LOG_CHANNEL)
The Binnacle
Endpoint PORT (BINNACLE_PORT), defaults to 8080 if not encrypted
Whether to pipe Rails logs as they are (verbose as shit) or just grab action_controller events and single line them (BINNACLE_RAILS_LOG_VERBOSE)
Whether to report exceptions to Binnacle
(BINNACLE_REPORT_EXCEPTIONS)
HTTP
outgoing logging options
Public Class Methods
# File lib/binnacle/configuration.rb, line 80 def initialize if ENV['BINNACLE_ENDPOINT'] self.endpoint ||= ENV['BINNACLE_ENDPOINT'].include?(',') ? ENV['BINNACLE_ENDPOINT'].split(',') : ENV['BINNACLE_ENDPOINT'] else if self.endpoint !~ /[^[:space:]]/ self.endpoint = (1..6).to_a.sample(3).map { |n| "api#{n}.binnacle-api.io" } end end self.logging_channel ||= ENV['BINNACLE_APP_LOG_CHANNEL'] self.error_channel ||= ENV['BINNACLE_APP_ERR_CHANNEL'] self.api_key ||= ENV['BINNACLE_API_KEY'] self.api_secret ||= ENV['BINNACLE_API_SECRET'] self.intercept_rails_logging = Configuration.set_boolean_flag_for(ENV['BINNACLE_RAILS_LOG']) self.rails_verbose_logging = Configuration.set_boolean_flag_for(ENV['BINNACLE_RAILS_LOG_VERBOSE']) self.report_exceptions = Configuration.set_boolean_flag_for(ENV['BINNACLE_REPORT_EXCEPTIONS']) self.ignored_exceptions ||= ENV['BINNACLE_IGNORED_EXCEPTIONS'] ? DEFAULT_IGNORED_EXCEPTIONS + ENV['BINNACLE_IGNORED_EXCEPTIONS'].split(',') : DEFAULT_IGNORED_EXCEPTIONS self.ignore_cascade_pass ||= true self.asynch_logging = Configuration.set_boolean_flag_for(ENV['BINNACLE_RAILS_LOG_ASYNCH'], true) @encrypted = Configuration.set_boolean_flag_for(ENV['BINNACLE_ENCRYPTED'], true) self.url_whitelist_patterns ||= ENV['BINNACLE_HTTP_LOGGING_WHITELIST'] ? ENV['BINNACLE_HTTP_LOGGING_WHITELIST'].split(',') : [] self.url_blacklist_patterns ||= ENV['BINNACLE_HTTP_LOGGING_BLACKLIST'] ? ENV['BINNACLE_HTTP_LOGGING_BLACKLIST'].split(',') : [] @url_whitelist_pattern = /.*/ @url_blacklist_pattern = nil self.log_binnacle_signals = Configuration.set_boolean_flag_for(ENV['BINNACLE_LOG_SIGNALS']) prepare! end
# File lib/binnacle/configuration.rb, line 234 def self.set_boolean_flag_for(value, default = false) !value.nil? ? value.downcase == 'true' : default end
Public Instance Methods
# File lib/binnacle/configuration.rb, line 160 def build_url(ip_or_host) ["#{protocol}://#{ip_or_host}", port].compact.join(":") end
# File lib/binnacle/configuration.rb, line 136 def can_setup_logger? !self.logging_channel.nil? end
# File lib/binnacle/configuration.rb, line 214 def encrypted=(value) @encrypted = value set_default_port set_urls end
# File lib/binnacle/configuration.rb, line 156 def encrypted? self.encrypted end
# File lib/binnacle/configuration.rb, line 209 def endpoint=(value) @endpoint = value set_urls end
# File lib/binnacle/configuration.rb, line 265 def ignore(test) ignore_tests.push(test) if test end
# File lib/binnacle/configuration.rb, line 273 def ignore?(event) ignore_tests.any? { |ignore_test| ignore_test.call(event) } end
Set conditions for events that should be ignored
Currently supported formats are:
- A single string representing a controller action, e.g. 'users#sign_in' - An array of strings representing controller actions - An object that responds to call with an event argument and returns true if the event should be ignored.
The action ignores are given to 'ignore_actions'. The callable ignores are given to 'ignore'. Both methods can be called multiple times, which just adds more ignore conditions to a list that is checked before logging.
# File lib/binnacle/configuration.rb, line 254 def ignore_actions(actions) ignore(lamba do |event| params = event.payload[:params] Array(actions).include?("#{params['controller']}##{params['action']}") end) end
# File lib/binnacle/configuration.rb, line 152 def ignore_cascade_pass? self.ignore_cascade_pass end
# File lib/binnacle/configuration.rb, line 269 def ignore_nothing @ignore_tests = [] end
# File lib/binnacle/configuration.rb, line 261 def ignore_tests @ignore_tests ||= [] end
# File lib/binnacle/configuration.rb, line 140 def intercept_rails_logging? self.intercept_rails_logging && !self.logging_channel.nil? end
# File lib/binnacle/configuration.rb, line 111 def prepare! set_default_port set_urls set_blacklist_patterns set_whitelist_patterns end
# File lib/binnacle/configuration.rb, line 164 def protocol self.encrypted? ? 'https' : 'http' end
# File lib/binnacle/configuration.rb, line 144 def rails_verbose_logging? self.rails_verbose_logging end
# File lib/binnacle/configuration.rb, line 128 def ready? urls? && self.api_key && self.api_secret end
# File lib/binnacle/configuration.rb, line 174 def set_blacklist_patterns blacklist_patterns = [] # don't log binnacle's posts unless self.log_binnacle_signals if @urls.is_a?(Array) @urls.each do |url| blacklist_patterns << /#{url}/ if url end elsif @urls blacklist_patterns << /#{@urls}/ end end self.url_blacklist_patterns.each do |pattern| blacklist_patterns << pattern end unless blacklist_patterns.empty? @url_blacklist_pattern = Regexp.union(blacklist_patterns) end end
# File lib/binnacle/configuration.rb, line 238 def set_default_port self.port ||= ENV['BINNACLE_PORT'] || (self.encrypted? ? nil : DEFAULT_PORT) end
# File lib/binnacle/configuration.rb, line 168 def set_urls if self.endpoint && (self.endpoint.is_a?(Array) ? !self.endpoint.empty? : (!self.endpoint !~ /[^[:space:]]/)) @urls = self.endpoint.is_a?(Array) ? self.endpoint.map { |ep| build_url(ep) } : build_url(endpoint) end end
# File lib/binnacle/configuration.rb, line 197 def set_whitelist_patterns whitelist_patterns = [] self.url_whitelist_patterns.each do |pattern| whitelist_patterns << pattern end unless whitelist_patterns.empty? @whitelist_pattern = Regexp.union(whitelist_patterns) end end
# File lib/binnacle/configuration.rb, line 220 def to_s [ :endpoint, :logging_channel, :error_channel, :api_key, :api_secret, :intercept_rails_logging, :report_exceptions, :ignore_cascade_pass, :encrypted, :asynch_logging ].map { |m| "#{m}: #{self.send(m)}" }.join(', ') end
# File lib/binnacle/configuration.rb, line 148 def trap? !self.report_exceptions.nil? && !self.error_channel.nil? end
# File lib/binnacle/configuration.rb, line 118 def url if @urls @urls.is_a?(Array) ? @urls.sample : @urls end end
# File lib/binnacle/configuration.rb, line 124 def urls @urls end
# File lib/binnacle/configuration.rb, line 132 def urls? (!@urls.nil? && !@urls.is_a?(Array)) || (@urls.is_a?(Array) && !@urls.empty?) end