Sha256: 1d45dd93b711e1ef3dc44f0a4344960216434d55c4f6a3dfa2ad63095b581f0d

Contents?: true

Size: 1.36 KB

Versions: 31

Compression:

Stored size: 1.36 KB

Contents

# Call EffectiveLog.info or EffectiveLog.success  EffectiveLog.error

class EffectiveLogger
  def self.log(message, status = EffectiveLogging.statuses.first, options = {})
    if options[:user].present? && !options[:user].kind_of?(User)
      raise ArgumentError.new("Log.log :user => ... argument must be a User object")
    end

    if options[:parent].present? && !options[:parent].kind_of?(Effective::Log)
      raise ArgumentError.new("Log.log :parent => ... argument must be an Effective::Log object")
    end

    if options[:associated].present? && !options[:associated].kind_of?(ActiveRecord::Base)
      raise ArgumentError.new("Log.log :associated => ... argument must be an ActiveRecord::Base object")
    end

    Effective::Log.new().tap do |log|
      log.message = message
      log.status = status

      log.user_id = options.delete(:user_id)
      log.user = options.delete(:user)
      log.parent = options.delete(:parent)
      log.associated = options.delete(:associated)

      log.details = options.delete_if { |k, v| v.blank? } if options.kind_of?(Hash)

      log.save
    end
  end

  # Dynamically add logging methods based on the defined statuses
  # EffectiveLogging.info 'my message'
  (EffectiveLogging.statuses || []).each do |status|
    self.singleton_class.send(:define_method, status) { |message, options={}| log(message, status, options) }
  end

end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
effective_logging-1.9.0 app/models/effective_logger.rb
effective_logging-1.8.1 app/models/effective_logger.rb
effective_logging-1.8.0 app/models/effective_logger.rb
effective_logging-1.7.1 app/models/effective_logger.rb
effective_logging-1.7.0 app/models/effective_logger.rb
effective_logging-1.6.0 app/models/effective_logger.rb
effective_logging-1.5.9 app/models/effective_logger.rb
effective_logging-1.5.8 app/models/effective_logger.rb
effective_logging-1.5.7 app/models/effective_logger.rb
effective_logging-1.5.6 app/models/effective_logger.rb
effective_logging-1.5.5 app/models/effective_logger.rb
effective_logging-1.5.4 app/models/effective_logger.rb
effective_logging-1.5.3 app/models/effective_logger.rb
effective_logging-1.5.2 app/models/effective_logger.rb
effective_logging-1.5.1 app/models/effective_logger.rb
effective_logging-1.5.0 app/models/effective_logger.rb
effective_logging-1.4.1 app/models/effective_logger.rb
effective_logging-1.4.0 app/models/effective_logger.rb
effective_logging-1.3.1 app/models/effective_logger.rb
effective_logging-1.3.0 app/models/effective_logger.rb