diaspora_federation/lib/diaspora_federation/logging.rb
Benjamin Neff 1dfe57ea7e
Add frozen_string_literal to all files
and remove redundant freezes
2019-10-21 03:11:12 +02:00

34 lines
1,010 B
Ruby

# frozen_string_literal: true
module DiasporaFederation
# Logging module for the diaspora* federation
#
# It uses the logging-gem if available.
module Logging
# Add +logger+ also as class method when included
# @param [Class] klass the class into which the module is included
def self.included(klass)
klass.extend(self)
end
private
# Get the logger for this class
#
# Use the logging-gem if available, else use a default logger.
def logger
@logger ||= begin
# Use logging-gem if available
return ::Logging::Logger[self] if defined?(::Logging::Logger)
# Use rails logger if running in rails and no logging-gem is available
return ::Rails.logger if defined?(::Rails)
# fallback logger
@logger = Logger.new(STDOUT)
@logger.level = Logger::INFO
@logger
end
end
end
end