Module: TaggedLogger

Defined in:
lib/tagged_logger/railtie.rb,
lib/tagged_logger/tagged_logger.rb

Defined Under Namespace

Classes: ClassSpecificLogger, Railtie, TagMatcher

Class Method Summary collapse

Class Method Details

.any_level(what, where = {}, &block) ⇒ Object



60
61
62
63
64
# File 'lib/tagged_logger/tagged_logger.rb', line 60

def any_level(what, where = {}, &block)
  [:debug, :info, :warn, :error, :fatal].each do |level|
    output(level, what, where, &block)
    end
end

.blocks_for(level, tag) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/tagged_logger/tagged_logger.rb', line 41

def blocks_for(level, tag)
  blocks = []
  tag_aliases(tag) do |tag_alias|
    tag_blocks(level, tag_alias) do |tag_block|
      blocks << [tag_alias, tag_block]
    end
  end
  blocks
end

.debug(what, where = {}, &block) ⇒ Object



55
# File 'lib/tagged_logger/tagged_logger.rb', line 55

def debug(what, where = {}, &block) output(:debug, what, where, &block) end

.error(what, where = {}, &block) ⇒ Object



58
# File 'lib/tagged_logger/tagged_logger.rb', line 58

def error(what, where = {}, &block) output(:error, what, where, &block) end

.fatal(what, where = {}, &block) ⇒ Object



59
# File 'lib/tagged_logger/tagged_logger.rb', line 59

def fatal(what, where = {}, &block) output(:fatal, what, where, &block) end

.format(&block) ⇒ Object



66
67
68
# File 'lib/tagged_logger/tagged_logger.rb', line 66

def format(&block)
  @formatter = block
end

.formatterObject



70
71
72
73
# File 'lib/tagged_logger/tagged_logger.rb', line 70

def formatter
  @formatter = lambda { |level, tag, message| "#{message}\n"} unless @formatter
  @formatter
end

.info(what, where = {}, &block) ⇒ Object



56
# File 'lib/tagged_logger/tagged_logger.rb', line 56

def info(what, where = {}, &block) output(:info, what, where, &block) end

.initObject



51
52
53
# File 'lib/tagged_logger/tagged_logger.rb', line 51

def init
  rules {}
end

.klass_has_method?(klass, method) ⇒ Boolean

Returns:

  • (Boolean)


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

def klass_has_method?(klass, method)
  klass.instance_methods(false).include?(RUBY_VERSION >= '1.9' ? method.to_sym : method.to_s)
end

.rename(renames) ⇒ Object



75
76
77
# File 'lib/tagged_logger/tagged_logger.rb', line 75

def rename(renames)
  renames.each { |from, to| @rename_rules[tag_matcher(from)] = to }
end

.resetObject



10
11
12
13
14
15
# File 'lib/tagged_logger/tagged_logger.rb', line 10

def reset
  @rename_rules = Dictionary.new
  @tag_blocks = Dictionary.new
  ObjectSpace.each_object(ClassSpecificLogger) { |obj| obj.detach }
  init
end

.restore_old_logger_methodsObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/tagged_logger/tagged_logger.rb', line 28

def restore_old_logger_methods
  return if @old_methods_restored
  @old_methods_restored = true
  @overridees.each do |klass|
    if klass_has_method?(klass, :tagged_logger_original_logger)
      klass.class_eval {alias_method :logger, :tagged_logger_original_logger}
    elsif klass_has_method?(klass, :logger)
      klass.class_eval {remove_method :logger}
    end
  end
  @overridees = []
end

.rules(options = {}, &block) ⇒ Object



17
18
19
20
21
22
# File 'lib/tagged_logger/tagged_logger.rb', line 17

def rules(options = {}, &block)
  @options = options
  @old_methods_restored = false
  inject_logger_method_in_call_chain(Object)
  instance_eval(&block)
end

.warn(what, where = {}, &block) ⇒ Object



57
# File 'lib/tagged_logger/tagged_logger.rb', line 57

def warn(what, where = {}, &block) output(:warn, what, where, &block) end