Sha256: 877e56f744baef4589837f3aabd38d71eb5952933ae307ee891520b579358b3f

Contents?: true

Size: 857 Bytes

Versions: 5

Compression:

Stored size: 857 Bytes

Contents

require 'logger'
module GetaroundUtils; end
module GetaroundUtils::Mixins; end

module GetaroundUtils::Mixins::Loggable
  def class_name
    @class_name ||= is_a?(Class) ? name : self.class.name
  end

  def base_append_infos_to_loggable(payload)
    payload[:origin] = class_name
    return unless respond_to?(:append_infos_to_loggable)

    append_infos_to_loggable(payload)
  end

  def base_loggable_logger
    @base_loggable_logger ||= if respond_to?(:logger)
      logger
    elsif defined?(Rails)
      Rails.logger
    else
      Logger.new(STDOUT)
    end
  end

  def loggable(severity, message, payload = {})
    payload = { message: message }.merge(payload)
    base_append_infos_to_loggable(payload)

    message = GetaroundUtils::Utils::DeepKeyValue.serialize(payload.compact)
    base_loggable_logger.send(severity.to_sym, message)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
getaround_utils-0.1.17 lib/getaround_utils/mixins/loggable.rb
getaround_utils-0.1.15 lib/getaround_utils/mixins/loggable.rb
getaround_utils-0.1.14 lib/getaround_utils/mixins/loggable.rb
getaround_utils-0.1.13 lib/getaround_utils/mixins/loggable.rb
getaround_utils-0.1.12 lib/getaround_utils/mixins/loggable.rb