Class: Logrithm::Log

Inherits:
Object
  • Object
show all
Includes:
Kungfuig
Defined in:
lib/logrithm/log.rb

Constant Summary collapse

JOINER =
"#{$/} #{option(:log, :joiners, :objects) || '⮩ '}".freeze
USE_GLOBAL_SELF =
option(:log, :global_self) || false
INSTANCE =
Log.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log = nil, **params) ⇒ Log

Returns a new instance of Log.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/logrithm/log.rb', line 12

def initialize(log = nil, **params)
  [
    File.join(__dir__, '..', '..', 'config', 'logrithm.yml'),
    (File.join((Rails.root || '.'), 'config', 'logrithm.yml') if Logrithm.rails?)
  ].compact.each do |cfg|
    kungfuig(cfg) if File.exist?(cfg)
  end
  kungfuig(params)
  ensure_logger(log) if log

  @leader = {}
  @colors = {}
end

Class Method Details

.app_rootObject



70
71
72
# File 'lib/logrithm/log.rb', line 70

def app_root
  File.realpath(INSTANCE.option(:log, :root) || Logrithm.rails? && Rails.root || File.join(__dir__, '..', '..'))
end

.option(*name) ⇒ Object



66
67
68
# File 'lib/logrithm/log.rb', line 66

def option(*name)
  INSTANCE.option(*name)
end

Instance Method Details

#flushObject



30
31
32
# File 'lib/logrithm/log.rb', line 30

def flush
  logdev.flush
end

#level=(level = nil) ⇒ Object



34
35
36
37
38
39
# File 'lib/logrithm/log.rb', line 34

def level=(level = nil)
  logger.level = level || case Logrithm.env
                          when :dev, :development, :test then Logger::DEBUG
                          else Logger::INFO
                          end
end

#loggerObject



26
27
28
# File 'lib/logrithm/log.rb', line 26

def logger
  ensure_logger
end