Class: Loggability::Logger::ObjectNameProxy
- Inherits:
-
Object
- Object
- Loggability::Logger::ObjectNameProxy
- Defined in:
- lib/loggability/logger.rb
Overview
Proxy for the Logger that injects the name of the object it wraps as the ‘progname’ of each log message.
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
The Loggability::Logger this proxy is for.
-
#progname ⇒ Object
readonly
The progname of the object the proxy is for.
Instance Method Summary collapse
-
#debug(msg = nil, &block) ⇒ Object
Delegate debug messages.
-
#error(msg = nil, &block) ⇒ Object
Delegate error messages.
-
#fatal(msg = nil, &block) ⇒ Object
Delegate fatal messages.
-
#info(msg = nil, &block) ⇒ Object
Delegate info messages.
-
#initialize(logger, object) ⇒ ObjectNameProxy
constructor
Create a proxy for the given
logger
that will inject the name of the specifiedobject
into the ‘progname’ of each log message. -
#inspect ⇒ Object
Return a human-readable string representation of the object, suitable for debugging.
-
#warn(msg = nil, &block) ⇒ Object
Delegate warn messages.
Constructor Details
#initialize(logger, object) ⇒ ObjectNameProxy
Create a proxy for the given logger
that will inject the name of the specified object
into the ‘progname’ of each log message.
33 34 35 36 |
# File 'lib/loggability/logger.rb', line 33 def initialize( logger, object ) @logger = logger @progname = make_progname( object ) end |
Instance Attribute Details
#logger ⇒ Object (readonly)
The Loggability::Logger this proxy is for.
43 44 45 |
# File 'lib/loggability/logger.rb', line 43 def logger @logger end |
#progname ⇒ Object (readonly)
The progname of the object the proxy is for.
46 47 48 |
# File 'lib/loggability/logger.rb', line 46 def progname @progname end |
Instance Method Details
#debug(msg = nil, &block) ⇒ Object
Delegate debug messages
50 51 52 |
# File 'lib/loggability/logger.rb', line 50 def debug( msg=nil, &block ) @logger.add( Logger::DEBUG, msg, @progname, &block ) end |
#error(msg = nil, &block) ⇒ Object
Delegate error messages
65 66 67 |
# File 'lib/loggability/logger.rb', line 65 def error( msg=nil, &block ) @logger.add( Logger::ERROR, msg, @progname, &block ) end |
#fatal(msg = nil, &block) ⇒ Object
Delegate fatal messages
70 71 72 |
# File 'lib/loggability/logger.rb', line 70 def fatal( msg=nil, &block ) @logger.add( Logger::FATAL, msg, @progname, &block ) end |
#info(msg = nil, &block) ⇒ Object
Delegate info messages
55 56 57 |
# File 'lib/loggability/logger.rb', line 55 def info( msg=nil, &block ) @logger.add( Logger::INFO, msg, @progname, &block ) end |
#inspect ⇒ Object
Return a human-readable string representation of the object, suitable for debugging.
76 77 78 |
# File 'lib/loggability/logger.rb', line 76 def inspect return "#<%p:%#016x for %s>" % [ self.class, self.object_id * 2, @progname ] end |
#warn(msg = nil, &block) ⇒ Object
Delegate warn messages
60 61 62 |
# File 'lib/loggability/logger.rb', line 60 def warn( msg=nil, &block ) @logger.add( Logger::WARN, msg, @progname, &block ) end |