class Conscriptor::HierarchicalContextLogger
Attributes
context[W]
Public Class Methods
new()
click to toggle source
# File lib/conscriptor/hierarchical_context_logger.rb, line 12 def initialize @context = [] @printed_context = [] end
Public Instance Methods
info(message)
click to toggle source
write a message with the context printed as well
# File lib/conscriptor/hierarchical_context_logger.rb, line 18 def info(message) @context.length.times do |level| puts_at_level @context[level], level if @context[0..level] != @printed_context[0..level] end @printed_context = @context.dup puts_at_level message, @context.length end
pop_context()
click to toggle source
ideally, use with_context
instead
# File lib/conscriptor/hierarchical_context_logger.rb, line 40 def pop_context @context.pop end
pop_context_to(level:)
click to toggle source
# File lib/conscriptor/hierarchical_context_logger.rb, line 44 def pop_context_to(level:) @context.pop while @context.length > level end
push_context(thing)
click to toggle source
ideally, use with_context
instead adds a level of context, e.g. 'school' or 'user'
# File lib/conscriptor/hierarchical_context_logger.rb, line 35 def push_context(thing) @context.push(thing) end
with_context(thing) { || ... }
click to toggle source
# File lib/conscriptor/hierarchical_context_logger.rb, line 26 def with_context(thing) push_context(thing) yield ensure pop_context end
Private Instance Methods
puts_at_level(message, level)
click to toggle source
# File lib/conscriptor/hierarchical_context_logger.rb, line 50 def puts_at_level(message, level) puts "#{' ' * level}#{message}" end