Class: Alexandria::LogWrapper

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/alexandria/logging.rb

Overview

A wrapper around a Logger, which allows code to define the source once (in the wrapper's initialization) and then call the log methods whithout needing to specify the source each time.

Instance Method Summary collapse

Constructor Details

#initialize(logger, source) ⇒ LogWrapper

Returns a new instance of LogWrapper.



76
77
78
79
# File 'lib/alexandria/logging.rb', line 76

def initialize(logger, source)
  @logger = logger
  @source = source
end

Instance Method Details

#<<(msg) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'lib/alexandria/logging.rb', line 83

def <<(msg)
  if msg.respond_to? :backtrace
    msg.backtrace.each do |line|
      @logger << "  #{line} \n"
    end
  else
    @logger << msg + "\n"
  end
end

#debug(progname = nil, &block) ⇒ Object



93
94
95
# File 'lib/alexandria/logging.rb', line 93

def debug(progname = nil, &block)
  @logger.debug(@source, progname, &block)
end

#error(progname = nil, &block) ⇒ Object



105
106
107
# File 'lib/alexandria/logging.rb', line 105

def error(progname = nil, &block)
  @logger.error(@source, progname, &block)
end

#fatal(progname = nil, &block) ⇒ Object



109
110
111
# File 'lib/alexandria/logging.rb', line 109

def fatal(progname = nil, &block)
  @logger.fatal(@source, progname, &block)
end

#info(progname = nil, &block) ⇒ Object



97
98
99
# File 'lib/alexandria/logging.rb', line 97

def info(progname = nil, &block)
  @logger.info(@source, progname, &block)
end

#warn(progname = nil, &block) ⇒ Object



101
102
103
# File 'lib/alexandria/logging.rb', line 101

def warn(progname = nil, &block)
  @logger.warn(@source, progname, &block)
end