Class: Logification::Logger

Inherits:
Object
  • Object
show all
Includes:
Helpers::LoggingMethods, Helpers::Wrapper
Defined in:
lib/logification/logger.rb

Constant Summary

Constants included from Helpers::LoggingMethods

Helpers::LoggingMethods::TAB

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Wrapper

#wrap

Methods included from Helpers::LoggingMethods

#debug, #error, #fatal, #info, #warn

Constructor Details

#initialize(options = {}) ⇒ Logger

Returns a new instance of Logger.



12
13
14
15
16
17
# File 'lib/logification/logger.rb', line 12

def initialize(options={})
  self.name = options[:name] || "logification"
  self.base_logger = options[:base_logger] || default_logger(@name)
  self.nested_count = options[:nested_count] || 0
  self.level = options[:level] || :debug
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/logification/logger.rb', line 44

def method_missing(meth, *args, &block)
  begin
    if block_given?
      if args.empty?
        base_logger.send(meth) { block }
      else
        base_logger.send(meth, *args, &block)
      end
    else
      if args.empty?
        base_logger.send(meth)
      else
        base_logger.send(meth, *args)
      end
    end
  rescue NoMethodError => ex
    super
  end
end

Instance Attribute Details

#base_loggerObject

Returns the value of attribute base_logger.



7
8
9
# File 'lib/logification/logger.rb', line 7

def base_logger
  @base_logger
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/logification/logger.rb', line 7

def name
  @name
end

#nested_countObject

Returns the value of attribute nested_count.



7
8
9
# File 'lib/logification/logger.rb', line 7

def nested_count
  @nested_count
end

Instance Method Details

#default_logger(name) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/logification/logger.rb', line 19

def default_logger(name)
  ::Logger.new(STDOUT).tap do |l|
    l.level = translate_level_in(:debug)
    l.formatter = Logification::Formatters::Colorized.new
    l.progname = self.name
  end
end

#duplicate(name, options = {}) ⇒ Object



39
40
41
42
# File 'lib/logification/logger.rb', line 39

def duplicate(name, options={})
  settings = current_settings.merge(options)
  self.class.new(settings.merge(name: name))
end

#levelObject



31
32
33
# File 'lib/logification/logger.rb', line 31

def level
  translate_level_out(base_logger.level)
end

#level=(value) ⇒ Object



35
36
37
# File 'lib/logification/logger.rb', line 35

def level=(value)
  base_logger.level = translate_level_in(value)
end