Class: Alexandria::LogWrapper
- Inherits:
-
Object
- Object
- Alexandria::LogWrapper
- 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
- #<<(msg) ⇒ Object
- #debug(progname = nil) ⇒ Object
- #error(progname = nil) ⇒ Object
- #fatal(progname = nil) ⇒ Object
- #info(progname = nil) ⇒ Object
-
#initialize(logger, source) ⇒ LogWrapper
constructor
A new instance of LogWrapper.
- #warn(progname = nil) ⇒ Object
Constructor Details
#initialize(logger, source) ⇒ LogWrapper
Returns a new instance of LogWrapper.
77 78 79 80 |
# File 'lib/alexandria/logging.rb', line 77 def initialize(logger, source) @logger = logger @source = source end |
Instance Method Details
#<<(msg) ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/alexandria/logging.rb', line 84 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) ⇒ Object
94 95 96 |
# File 'lib/alexandria/logging.rb', line 94 def debug(progname = nil, &) @logger.debug(@source, progname, &) end |
#error(progname = nil) ⇒ Object
106 107 108 |
# File 'lib/alexandria/logging.rb', line 106 def error(progname = nil, &) @logger.error(@source, progname, &) end |
#fatal(progname = nil) ⇒ Object
110 111 112 |
# File 'lib/alexandria/logging.rb', line 110 def fatal(progname = nil, &) @logger.fatal(@source, progname, &) end |
#info(progname = nil) ⇒ Object
98 99 100 |
# File 'lib/alexandria/logging.rb', line 98 def info(progname = nil, &) @logger.info(@source, progname, &) end |
#warn(progname = nil) ⇒ Object
102 103 104 |
# File 'lib/alexandria/logging.rb', line 102 def warn(progname = nil, &) @logger.warn(@source, progname, &) end |