Guest User

Untitled

a guest
Feb 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. class Module
  2.  
  3. # call-seq:
  4. # logger_name #=> string
  5. #
  6. # Returns a predictable logger name for the current module or class. If
  7. # used within an anonymous class, the first non-anonymous class name will
  8. # be used as the logger name. If used within a meta-class, the name of the
  9. # actual class will be used as the logger name. If used within an
  10. # anonymous module, the string 'anonymous' will be returned.
  11. #
  12. def logger_name
  13. return name unless name.empty?
  14.  
  15. # check if this is a metaclass (or eigenclass)
  16. if ancestors.include? Class
  17. inspect =~ %r/#<Class:([^#>]+)>/
  18. return $1
  19. end
  20.  
  21. # see if we have a superclass
  22. if respond_to? :superclass
  23. return superclass.logger_name
  24. end
  25.  
  26. # we are an anonymous module
  27. ::Logging.log_internal(-2) {
  28. 'cannot return a predictable, unique name for anonymous modules'
  29. }
  30. return 'anonymous'
  31. end
  32. end
Add Comment
Please, Sign In to add comment