Class: Gallus::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/gallus/log.rb

Constant Summary collapse

@@global_context_mutex =
Mutex.new
@@global_context =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, name) {|_self| ... } ⇒ Log

Returns a new instance of Log.

Yields:

  • (_self)

Yield Parameters:

  • _self (Gallus::Log)

    the object that the method was called on



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/gallus/log.rb', line 52

def initialize(parent, name, &block)
  @parent, @name = parent, name.to_s

  if parent
    @output = (@parent.output || []).dup
    @serialization = @parent.serialization
    self.level = @parent.level
  end

  @output ||= []
  @serialization ||= Serialization::Inspect.new

  yield self if block_given?
end

Instance Attribute Details

#levelObject

Returns the value of attribute level.



49
50
51
# File 'lib/gallus/log.rb', line 49

def level
  @level
end

#nameObject

Returns the value of attribute name.



49
50
51
# File 'lib/gallus/log.rb', line 49

def name
  @name
end

#outputObject (readonly)

Returns the value of attribute output.



50
51
52
# File 'lib/gallus/log.rb', line 50

def output
  @output
end

#serializationObject

Returns the value of attribute serialization.



49
50
51
# File 'lib/gallus/log.rb', line 49

def serialization
  @serialization
end

Class Method Details

.[](name) ⇒ Object



11
12
13
# File 'lib/gallus/log.rb', line 11

def [](name)
  configure(name)
end

.configure(name = '', &block) ⇒ Object



7
8
9
# File 'lib/gallus/log.rb', line 7

def configure(name = '', &block)
  Repository.get_or_create_logger(name, &block)
end

.current_thread_context {|(Thread.current[:log_context] ||= {})| ... } ⇒ Object

Yields:

  • ((Thread.current[:log_context] ||= {}))


40
41
42
# File 'lib/gallus/log.rb', line 40

def current_thread_context
  yield (Thread.current[:log_context] ||= {})
end

.define_log_methods!(log_level) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gallus/log.rb', line 19

def define_log_methods!(log_level)
  Level.each do |level|
    method_name = level.name.downcase
    remove_method(method_name) if method_defined?(method_name)

    if level >= log_level
      define_method(method_name) do |message, payload = {}|
        log(level, message, payload)
      end
    else
      define_method(method_name) do |message, payload = {}|
        # supressed...
      end
    end
  end
end

.delete(name) ⇒ Object



15
16
17
# File 'lib/gallus/log.rb', line 15

def delete(name)
  Repository.delete_with_children(name)
end

.global_contextObject



36
37
38
# File 'lib/gallus/log.rb', line 36

def global_context
  @@global_context_mutex.synchronize { yield @@global_context }
end

.rootObject



44
45
46
# File 'lib/gallus/log.rb', line 44

def root
  @@root
end

Instance Method Details

#contextObject



74
75
76
# File 'lib/gallus/log.rb', line 74

def context
  @context ||= {}
end