Class: Module
- Inherits:
-
Object
- Object
- Module
- Defined in:
- lib/logging/utils.rb
Overview
Instance Method Summary collapse
-
#logger_name ⇒ Object
call-seq: logger_name #=> string.
Instance Method Details
#logger_name ⇒ Object
call-seq:
logger_name #=> string
Returns a predictable logger name for the current module or class. If used within an anonymous class, the first non-anonymous class name will be used as the logger name. If used within a meta-class, the name of the actual class will be used as the logger name. If used within an anonymous module, the string ‘anonymous’ will be returned.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/logging/utils.rb', line 47 def logger_name return name unless name.nil? or name.empty? # check if this is a metaclass (or eigenclass) if ancestors.include? Class inspect =~ %r/#<Class:([^#>]+)>/ return $1 end # see if we have a superclass if respond_to? :superclass return superclass.logger_name end # we are an anonymous module ::Logging.log_internal(-2) { 'cannot return a predictable, unique name for anonymous modules' } return 'anonymous' end |