Class: Sapience::Configuration
- Inherits:
-
Object
- Object
- Sapience::Configuration
- Defined in:
- lib/sapience/configuration.rb,
lib/sapience/configuration/grape.rb
Overview
rubocop:disable ClassVars
Defined Under Namespace
Classes: Grape
Constant Summary collapse
- DEFAULT =
{ log_level: :info, application: "Sapience", host: nil, ap_options: { multiline: false }, appenders: [{ stream: { io: STDOUT, formatter: :color } }], }.freeze
Instance Attribute Summary collapse
-
#ap_options ⇒ Object
Returns the value of attribute ap_options.
-
#appenders ⇒ Object
Returns the value of attribute appenders.
-
#application ⇒ Object
Returns the value of attribute application.
-
#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.
-
#host ⇒ Object
Returns [String] name of this host for logging purposes Note: Not all appenders use ‘host`.
Instance Method Summary collapse
- #default_level_index ⇒ 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_to_index(level) ⇒ Object
Internal method to return the log level as an internal index Also supports mapping the ::Logger levels to Sapience levels.
Constructor Details
#initialize(options = {}) ⇒ Configuration
Initial default Level for all new instances of Sapience::Logger
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sapience/configuration.rb', line 19 def initialize( = {}) # rubocop:disable AbcSize fail ArgumentError, "options need to be a hash" unless .is_a?(Hash) @options = DEFAULT.merge(.deep_symbolize_keys!) self.default_level = @options[:log_level].to_sym self.backtrace_level = @options[:log_level].to_sym self.application = @options[:application] self.host = @options[:host] self. = @options[:ap_options] self.appenders = @options[:appenders] end |
Instance Attribute Details
#ap_options ⇒ Object
Returns the value of attribute ap_options.
8 9 10 |
# File 'lib/sapience/configuration.rb', line 8 def @ap_options end |
#appenders ⇒ Object
Returns the value of attribute appenders.
8 9 10 |
# File 'lib/sapience/configuration.rb', line 8 def appenders @appenders end |
#application ⇒ Object
Returns the value of attribute application.
8 9 10 |
# File 'lib/sapience/configuration.rb', line 8 def application @application end |
#backtrace_level ⇒ Object
Returns the value of attribute backtrace_level.
6 7 8 |
# File 'lib/sapience/configuration.rb', line 6 def backtrace_level @backtrace_level end |
#backtrace_level_index ⇒ Object (readonly)
Returns the value of attribute backtrace_level_index.
6 7 8 |
# File 'lib/sapience/configuration.rb', line 6 def backtrace_level_index @backtrace_level_index end |
#default_level ⇒ Object
Returns the value of attribute default_level.
6 7 8 |
# File 'lib/sapience/configuration.rb', line 6 def default_level @default_level end |
#host ⇒ Object
Returns [String] name of this host for logging purposes Note: Not all appenders use ‘host`
91 92 93 |
# File 'lib/sapience/configuration.rb', line 91 def host @host ||= Socket.gethostname end |
Instance Method Details
#default_level_index ⇒ Object
68 69 70 |
# File 'lib/sapience/configuration.rb', line 68 def default_level_index Thread.current[:sapience_silence] || @default_level_index end |
#index_to_level(level_index) ⇒ Object
Returns the symbolic level for the supplied level index
38 39 40 |
# File 'lib/sapience/configuration.rb', line 38 def index_to_level(level_index) LEVELS[level_index] 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
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/sapience/configuration.rb', line 44 def level_to_index(level) # rubocop:disable AbcSize, PerceivedComplexity, CyclomaticComplexity return if level.nil? index = if level.is_a?(Symbol) LEVELS.index(level) elsif level.is_a?(String) level = level.downcase.to_sym LEVELS.index(level) elsif level.is_a?(Integer) && defined?(::Logger::Severity) # Mapping of Rails and Ruby Logger levels to Sapience levels @@map_levels ||= begin levels = [] ::Logger::Severity.constants.each do |constant| levels[::Logger::Severity.const_get(constant)] = LEVELS.find_index(constant.downcase.to_sym) || LEVELS.find_index(:error) # rubocop:disable LineLength end levels end @@map_levels[level] end fail "Invalid level:#{level.inspect} being requested. Must be one of #{LEVELS.inspect}" unless index index end |