Class: Oasis::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/oasis/logger.rb

Constant Summary collapse

LOG_LEVELS =
{
  :trace => 1,
  :debug => 2,
  :warn => 3
}.freeze
RAILS_LOG_METHOD =
{
  :trace => :debug,
  :debug => :debug,
  :warn => :warn
}.freeze

Class Method Summary collapse

Class Method Details

.debug(msg) ⇒ Object



25
# File 'lib/oasis/logger.rb', line 25

def debug(msg); log(msg, :debug); end

.levelObject



14
15
16
# File 'lib/oasis/logger.rb', line 14

def level
  @level || :warn
end

.level=(v) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/oasis/logger.rb', line 17

def level=(v)
  unless LOG_LEVELS.has_key?(v)
    errmsg = "#{v.inspect} is not a log level. Please use one of #{LOG_LEVELS.keys.map(&:inspect).join(", ")}"
    raise ArgumentError, errmsg
  end
  @level = v
end

.log(msg, level) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/oasis/logger.rb', line 27

def log(msg, level)
  return unless LOG_LEVELS[level] >= LOG_LEVELS[self.level]
  msg = "** [OASIS] : #{msg}"
  if defined?(Rails)
    Rails.logger.send(RAILS_LOG_METHOD[level], msg)
  elsif defined?(RAILS_DEFAULT_LOGGER)
    RAILS_DEFAULT_LOGGER.send(RAILS_LOG_METHOD[level], msg)
  else
    $stderr.puts msg
  end
end

.trace(msg) ⇒ Object



24
# File 'lib/oasis/logger.rb', line 24

def trace(msg); log(msg, :trace); end

.warn(msg) ⇒ Object



26
# File 'lib/oasis/logger.rb', line 26

def warn(msg);  log(msg, :warn);  end