Class: Sapience::Configuration
- Inherits:
-
Object
- Object
- Sapience::Configuration
- Defined in:
- lib/sapience/configuration.rb
Overview
rubocop:disable ClassVars
Constant Summary collapse
- SUPPORTED_EXECUTORS =
%i(single_thread_executor immediate_executor).freeze
- DEFAULT =
{ log_level: :info, host: nil, ap_options: { multiline: false }, appenders: [{ stream: { io: STDOUT, formatter: :color } }], log_executor: :single_thread_executor, metrics: { datadog: { url: Sapience::DEFAULT_STATSD_URL } }, error_handler: { silent: {} }, filter_parameters: %w(password password_confirmation), silent_active_record: false, silent_rails: false, silent_rack: false, rails_ac_metrics: true, grape_metrics: true, }.freeze
Instance Attribute Summary collapse
-
#ap_options ⇒ Object
Returns the value of attribute ap_options.
-
#app_name ⇒ Object
Returns the value of attribute app_name.
-
#appenders ⇒ Object
Returns the value of attribute appenders.
-
#backtrace_level ⇒ Object
Returns the value of attribute backtrace_level.
-
#backtrace_level_index ⇒ Object
readonly
Returns the value of attribute backtrace_level_index.
-
#default_level ⇒ Object
Returns the value of attribute default_level.
-
#error_handler ⇒ Object
Returns the value of attribute error_handler.
-
#filter_parameters ⇒ Object
Returns the value of attribute filter_parameters.
-
#grape_metrics ⇒ Object
Returns the value of attribute grape_metrics.
-
#host ⇒ Object
Returns [String] name of this host for logging purposes Note: Not all appenders use ‘host`.
-
#log_executor ⇒ Object
Returns the value of attribute log_executor.
-
#metrics ⇒ Object
Returns the value of attribute metrics.
-
#rails_ac_metrics ⇒ Object
Returns the value of attribute rails_ac_metrics.
-
#silent_active_record ⇒ Object
Returns the value of attribute silent_active_record.
-
#silent_rack ⇒ Object
Returns the value of attribute silent_rack.
-
#silent_rails ⇒ Object
Returns the value of attribute silent_rails.
Instance Method Summary collapse
- #default_level_index ⇒ Object
- #fail_with_unkown_log_level!(level) ⇒ Object
-
#index_to_level(level_index) ⇒ Object
Returns the symbolic level for the supplied level index.
-
#initialize(options = {}) ⇒ Configuration
constructor
Initial default Level for all new instances of Sapience::Logger.
- #level_by_index_or_error(constant) ⇒ Object
-
#level_to_index(level) ⇒ Object
Internal method to return the log level as an internal index Also supports mapping the ::Logger levels to Sapience levels.
-
#map_levels ⇒ Object
Mapping of Rails and Ruby Logger levels to Sapience levels.
- #validate_log_executor!(log_executor) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Configuration
Initial default Level for all new instances of Sapience::Logger
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/sapience/configuration.rb', line 32 def initialize( = {}) # rubocop:disable AbcSize fail ArgumentError, "options need to be a hash #{.inspect}" unless .is_a?(Hash) @options = DEFAULT.merge(.dup.deep_symbolize_keyz!) @options[:log_executor] &&= @options[:log_executor].to_sym validate_log_executor!(@options[:log_executor]) self.default_level = @options[:log_level].to_sym self.backtrace_level = @options[:log_level].to_sym self.host = @options[:host] self.app_name = @options[:app_name] self. = @options[:ap_options] self.appenders = @options[:appenders] self.log_executor = @options[:log_executor] self.filter_parameters = @options[:filter_parameters] self.metrics = @options[:metrics] self.error_handler = @options[:error_handler] self.silent_active_record = @options[:silent_active_record] self.silent_rails = @options[:silent_rails] self.silent_rack = @options[:silent_rack] self.rails_ac_metrics = @options[:rails_ac_metrics] self.grape_metrics = @options[:grape_metrics] end |
Instance Attribute Details
#ap_options ⇒ Object
Returns the value of attribute ap_options.
10 11 12 |
# File 'lib/sapience/configuration.rb', line 10 def @ap_options end |
#app_name ⇒ Object
Returns the value of attribute app_name.
10 11 12 |
# File 'lib/sapience/configuration.rb', line 10 def app_name @app_name end |
#appenders ⇒ Object
Returns the value of attribute appenders.
10 11 12 |
# File 'lib/sapience/configuration.rb', line 10 def appenders @appenders end |
#backtrace_level ⇒ Object
Returns the value of attribute backtrace_level.
8 9 10 |
# File 'lib/sapience/configuration.rb', line 8 def backtrace_level @backtrace_level end |
#backtrace_level_index ⇒ Object (readonly)
Returns the value of attribute backtrace_level_index.
8 9 10 |
# File 'lib/sapience/configuration.rb', line 8 def backtrace_level_index @backtrace_level_index end |
#default_level ⇒ Object
Returns the value of attribute default_level.
8 9 10 |
# File 'lib/sapience/configuration.rb', line 8 def default_level @default_level end |
#error_handler ⇒ Object
Returns the value of attribute error_handler.
10 11 12 |
# File 'lib/sapience/configuration.rb', line 10 def error_handler @error_handler end |
#filter_parameters ⇒ Object
Returns the value of attribute filter_parameters.
10 11 12 |
# File 'lib/sapience/configuration.rb', line 10 def filter_parameters @filter_parameters end |
#grape_metrics ⇒ Object
Returns the value of attribute grape_metrics.
10 11 12 |
# File 'lib/sapience/configuration.rb', line 10 def grape_metrics @grape_metrics end |
#host ⇒ Object
Returns [String] name of this host for logging purposes Note: Not all appenders use ‘host`
124 125 126 |
# File 'lib/sapience/configuration.rb', line 124 def host @host ||= Socket.gethostname end |
#log_executor ⇒ Object
Returns the value of attribute log_executor.
10 11 12 |
# File 'lib/sapience/configuration.rb', line 10 def log_executor @log_executor end |
#metrics ⇒ Object
Returns the value of attribute metrics.
10 11 12 |
# File 'lib/sapience/configuration.rb', line 10 def metrics @metrics end |
#rails_ac_metrics ⇒ Object
Returns the value of attribute rails_ac_metrics.
10 11 12 |
# File 'lib/sapience/configuration.rb', line 10 def rails_ac_metrics @rails_ac_metrics end |
#silent_active_record ⇒ Object
Returns the value of attribute silent_active_record.
10 11 12 |
# File 'lib/sapience/configuration.rb', line 10 def silent_active_record @silent_active_record end |
#silent_rack ⇒ Object
Returns the value of attribute silent_rack.
10 11 12 |
# File 'lib/sapience/configuration.rb', line 10 def silent_rack @silent_rack end |
#silent_rails ⇒ Object
Returns the value of attribute silent_rails.
10 11 12 |
# File 'lib/sapience/configuration.rb', line 10 def silent_rails @silent_rails end |
Instance Method Details
#default_level_index ⇒ Object
102 103 104 |
# File 'lib/sapience/configuration.rb', line 102 def default_level_index Thread.current[:sapience_silence] || @default_level_index end |
#fail_with_unkown_log_level!(level) ⇒ Object
83 84 85 86 87 |
# File 'lib/sapience/configuration.rb', line 83 def fail_with_unkown_log_level!(level) fail UnkownLogLevel, "Invalid level:#{level.inspect} being requested." \ " Must be one of #{LEVELS.inspect}" end |
#index_to_level(level_index) ⇒ Object
Returns the symbolic level for the supplied level index
62 63 64 |
# File 'lib/sapience/configuration.rb', line 62 def index_to_level(level_index) LEVELS[level_index] end |
#level_by_index_or_error(constant) ⇒ Object
98 99 100 |
# File 'lib/sapience/configuration.rb', line 98 def level_by_index_or_error(constant) LEVELS.find_index(constant.downcase.to_sym) || LEVELS.find_index(:error) end |
#level_to_index(level) ⇒ Object
Internal method to return the log level as an internal index Also supports mapping the ::Logger levels to Sapience levels
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/sapience/configuration.rb', line 68 def level_to_index(level) return if level.nil? case level when Symbol LEVELS.index(level) when String LEVELS.index(level.downcase.to_sym) when Integer map_levels[level] || fail_with_unkown_log_level!(level) else fail_with_unkown_log_level!(level) end end |
#map_levels ⇒ Object
Mapping of Rails and Ruby Logger levels to Sapience levels
90 91 92 93 94 95 96 |
# File 'lib/sapience/configuration.rb', line 90 def map_levels return [] unless defined?(::Logger::Severity) @@map_levels ||= ::Logger::Severity.constants.each_with_object([]) do |constant, levels| levels[::Logger::Severity.const_get(constant)] = level_by_index_or_error(constant) end end |
#validate_log_executor!(log_executor) ⇒ Object
128 129 130 131 |
# File 'lib/sapience/configuration.rb', line 128 def validate_log_executor!(log_executor) return true if SUPPORTED_EXECUTORS.include?(log_executor) fail InvalidLogExecutor, "#{log_executor} is unsupported. Use (#{SUPPORTED_EXECUTORS.join(", ")})" end |