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
INSTANCE =
Log.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Log.



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/logrithm/log.rb', line 23

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



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

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

.log(message) ⇒ Object



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

def self.log(message)
  if $♯
    puts "Self: [#{$♯}], Message: [#{message}]."
  else
    # idx = caller.index { |s| s.include? __FILE__ } to work inside pry
    Utils::Syringe.inject(*Utils::Helpers.dirty_lookup_class_method(*caller.first[/\A(.+):(\d+)(?=:in)/].split(/:(?=\d+\z)/)))
    puts "Message: [#{message}]."
  end
rescue
  puts "Message: [#{message}]."
end

.option(*name) ⇒ Object



62
63
64
# File 'lib/logrithm/log.rb', line 62

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

Instance Method Details

#flushObject



41
42
43
# File 'lib/logrithm/log.rb', line 41

def flush
  logdev.flush
end

#level=(level = nil) ⇒ Object



45
46
47
48
49
50
# File 'lib/logrithm/log.rb', line 45

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

#loggerObject



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

def logger
  ensure_logger
end