Class: Logbert::Logger

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(factory, level_manager, name) ⇒ Logger

Returns a new instance of Logger.



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

def initialize(factory, level_manager, name)
  @factory       = factory
  @level_manager = level_manager

  @name     = name.dup.freeze
  @handlers = []
end

Instance Attribute Details

#factoryObject (readonly)

Returns the value of attribute factory.



10
11
12
# File 'lib/logbert/logger.rb', line 10

def factory
  @factory
end

#handlersObject (readonly)

Returns the value of attribute handlers.



10
11
12
# File 'lib/logbert/logger.rb', line 10

def handlers
  @handlers
end

#level_managerObject (readonly)

Returns the value of attribute level_manager.



10
11
12
# File 'lib/logbert/logger.rb', line 10

def level_manager
  @level_manager
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/logbert/logger.rb', line 10

def name
  @name
end

Instance Method Details

#levelObject



24
25
26
# File 'lib/logbert/logger.rb', line 24

def level
  @level || self.parent.level
end

#level=(x) ⇒ Object



28
29
30
# File 'lib/logbert/logger.rb', line 28

def level=(x)
  @level = @level_manager[x]
end

#level_inherited?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/logbert/logger.rb', line 20

def level_inherited?
  !@level
end

#log(level, *args, &block) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/logbert/logger.rb', line 45

def log(level, *args, &block)
  content, options = self.prepare_message_args(*args, &block)

  exception = options[:exc_info]
  if exception
    # If the user passed in an exception, then use that one.
    # Otherwise, check the magic $! variable to see if an
    # exception is currently being handled.
    exception = $! unless exception.is_a? Exception
  end

  message = Logbert::Message.create(self, @level_manager[level], exception, options, content, &block)
  handle_message(message)
end

#parentObject



33
34
35
36
37
38
39
# File 'lib/logbert/logger.rb', line 33

def parent
  unless @parent_defined
    @parent = @factory.parent_for(self)
    @parent_defined = true
  end
  return @parent
end

#rootObject



41
42
43
# File 'lib/logbert/logger.rb', line 41

def root
  self.factory.root
end

#to_sObject



61
62
63
# File 'lib/logbert/logger.rb', line 61

def to_s
  @name
end