class LittleMonster::Core::TaggedLogger

Constants

LEVELS

Attributes

parent_logger[RW]
tags[R]

Public Class Methods

new() click to toggle source
# File lib/little_monster/core/tagged_logger.rb, line 12
def initialize
  @tags = Hash.new({})
  @parent_logger = nil
end
tags_to_string(hash) click to toggle source
# File lib/little_monster/core/tagged_logger.rb, line 8
def self.tags_to_string(hash)
  hash.map { |k, v| "[#{k}:#{v}]" }.join
end

Public Instance Methods

default_tags() click to toggle source
# File lib/little_monster/core/tagged_logger.rb, line 39
def default_tags
  @tags[:default]
end
default_tags=(t) click to toggle source
# File lib/little_monster/core/tagged_logger.rb, line 43
def default_tags=(t)
  tags_for(:default, t)
end
log_tags(level, tags_hash) click to toggle source
# File lib/little_monster/core/tagged_logger.rb, line 58
def log_tags(level, tags_hash)
  public_send(level, tags_to_string(tags_hash))
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/little_monster/core/tagged_logger.rb, line 17
def method_missing(method, *args, &block)
  if method.to_s.ends_with? 'tags='
    tag_key = method.to_s.split('_').first.to_sym
    return public_send('tags_for', tag_key, *args) if LEVELS.include? tag_key
  end

  if method.to_s.ends_with? 'tags'
    tag_key = method.to_s.split('_').first.to_sym
    return @tags[tag_key] if LEVELS.include? tag_key
  end

  if LEVELS.include? method.to_sym
    return LittleMonster.logger.public_send method, tag_message(method.to_sym, *args)
  end

  super method, *args, &block
end
tag_message(level, message = '') click to toggle source
# File lib/little_monster/core/tagged_logger.rb, line 47
def tag_message(level, message = '')
  prefix_string =  tags_to_string @tags[:default].merge(@tags[level])
  prefix_string << ' -- ' unless prefix_string.blank?

  unless @parent_logger.nil?
    prefix_string = @parent_logger.tag_message level, prefix_string
  end

  [prefix_string, message].join
end
tags_for(key, t = {}) click to toggle source
# File lib/little_monster/core/tagged_logger.rb, line 35
def tags_for(key, t = {})
  @tags[key] = t
end
tags_to_string(hash) click to toggle source
# File lib/little_monster/core/tagged_logger.rb, line 62
def tags_to_string(hash)
  self.class.tags_to_string hash
end