Class: Sapience::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/sapience/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



9
10
11
12
13
14
15
16
17
# File 'lib/sapience/configuration.rb', line 9

def initialize
  # Initial default Level for all new instances of Sapience::Logger
  self.default_level   = :info
  self.backtrace_level = :info
  self.application     = "Sapience"
  self.host            = nil
  self.ap_options      = { multiline: false }
  self.appenders       = [ { file: {io: STDOUT, formatter: :color } } ]
end

Instance Attribute Details

#ap_optionsObject

Returns the value of attribute ap_options.



7
8
9
# File 'lib/sapience/configuration.rb', line 7

def ap_options
  @ap_options
end

#appendersObject

Returns the value of attribute appenders.



7
8
9
# File 'lib/sapience/configuration.rb', line 7

def appenders
  @appenders
end

#applicationObject

Returns the value of attribute application.



7
8
9
# File 'lib/sapience/configuration.rb', line 7

def application
  @application
end

#backtrace_levelObject

Returns the value of attribute backtrace_level.



5
6
7
# File 'lib/sapience/configuration.rb', line 5

def backtrace_level
  @backtrace_level
end

#backtrace_level_indexObject (readonly)

Returns the value of attribute backtrace_level_index.



5
6
7
# File 'lib/sapience/configuration.rb', line 5

def backtrace_level_index
  @backtrace_level_index
end

#default_levelObject

Returns the value of attribute default_level.



5
6
7
# File 'lib/sapience/configuration.rb', line 5

def default_level
  @default_level
end

#hostObject

Returns [String] name of this host for logging purposes Note: Not all appenders use ‘host`



80
81
82
# File 'lib/sapience/configuration.rb', line 80

def host
  @host ||= Socket.gethostname
end

Instance Method Details

#default_level_indexObject



57
58
59
# File 'lib/sapience/configuration.rb', line 57

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



27
28
29
# File 'lib/sapience/configuration.rb', line 27

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



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/sapience/configuration.rb', line 33

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)
        end
        levels
      end
      @@map_levels[level]
    end
  fail "Invalid level:#{level.inspect} being requested. Must be one of #{LEVELS.inspect}" unless index
  index
end