Class: Marty::Log

Inherits:
Base show all
Defined in:
app/models/marty/log.rb

Class Method Summary collapse

Methods inherited from Base

get_final_attrs, get_struct_attrs, make_hash, make_openstruct, mcfly_pt

Methods inherited from ActiveRecord::Base

joins, old_joins

Class Method Details

.cleanup(days_to_keep) ⇒ Object



18
19
20
21
22
23
# File 'app/models/marty/log.rb', line 18

def self.cleanup(days_to_keep)
  raise "Must give numeric value. (Got '#{days_to_keep}')" unless
    (Float(days_to_keep) rescue false)

  where('timestamp <= ?', Time.zone.now - days_to_keep.to_i.days).delete_all
end

.write_log(type, message, details) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'app/models/marty/log.rb', line 6

def self.write_log(type, message, details)
  begin
    create!(message_type: type,
            message: message,
            details: details,
            timestamp: Time.zone.now)
  rescue StandardError => e
    Marty::Util.logger.error("Marty::Logger failure: #{e.message}")
  end
  true
end