module LoggingLibrary::Mixins::Loggable
Mixin for adding a lazily-instantiated `logger` attribute to your class, with reasonable defaults based on the class name.
Public Instance Methods
logger()
click to toggle source
# File lib/logging_library/mixins/loggable.rb, line 10 def logger @logger ||= LoggerFactory.create(_logger_name) end
Private Instance Methods
_logger_name()
click to toggle source
# File lib/logging_library/mixins/loggable.rb, line 16 def _logger_name # Handle both `extend` and `include` use cases. if self.class == Class || self.class == Module _short_class_name(to_s) else _short_class_name(self.class.name) end end
_short_class_name(full_name)
click to toggle source
# File lib/logging_library/mixins/loggable.rb, line 25 def _short_class_name(full_name) # ClassThatIncludesLoggable vs # Ecraft::LoggingLibrary::ClassThatIncludesLoggable. The latter feels # overly detailed; there are hopefully not that many classes with the # same name in an application... full_name.split('::').last end