Created
September 4, 2008 19:08
-
-
Save TwP/8849 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Module | |
# 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. | |
# | |
def logger_name | |
return name unless 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 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment