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.



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

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.



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

def factory
  @factory
end

#handlersObject (readonly)

Returns the value of attribute handlers.



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

def handlers
  @handlers
end

#level_managerObject (readonly)

Returns the value of attribute level_manager.



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

def level_manager
  @level_manager
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#levelObject



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

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

#level=(x) ⇒ Object



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

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

#level_inherited?Boolean

Returns:

  • (Boolean)


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

def level_inherited?
  !@level
end

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



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

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



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

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

#rootObject



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

def root
  self.factory.root
end

#to_sObject



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

def to_s
  @name
end