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_rails: false, }.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.
-
#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.
-
#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
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sapience/configuration.rb', line 27 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_rails = @options[:silent_rails] 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 |
#host ⇒ Object
Returns [String] name of this host for logging purposes Note: Not all appenders use ‘host`
115 116 117 |
# File 'lib/sapience/configuration.rb', line 115 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 |
#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
93 94 95 |
# File 'lib/sapience/configuration.rb', line 93 def default_level_index Thread.current[:sapience_silence] || @default_level_index end |
#fail_with_unkown_log_level!(level) ⇒ Object
74 75 76 77 78 |
# File 'lib/sapience/configuration.rb', line 74 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
53 54 55 |
# File 'lib/sapience/configuration.rb', line 53 def index_to_level(level_index) LEVELS[level_index] end |
#level_by_index_or_error(constant) ⇒ Object
89 90 91 |
# File 'lib/sapience/configuration.rb', line 89 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
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/sapience/configuration.rb', line 59 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
81 82 83 84 85 86 87 |
# File 'lib/sapience/configuration.rb', line 81 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
119 120 121 122 |
# File 'lib/sapience/configuration.rb', line 119 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 |