Class: NotifyMe::Log::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/notifyme/log.rb

Direct Known Subclasses

File, Mail, Stdout

Constant Summary collapse

LOG_FREQUENCE =

30s, 1min, 5min, 10min, 30min, 1hour, 6hours, 12hours, 1day, 1week, 1month (unit: seconds)

[30, 60, 300, 600, 1800, 3600, 21600, 43200, 86400, 604800, 2592000]
@@log_history =

store the time of the errors for each task

{}

Instance Method Summary collapse

Constructor Details

#initialize(parameters = {}) ⇒ Logger

Returns a new instance of Logger.



34
35
36
# File 'lib/notifyme/log.rb', line 34

def initialize(parameters = {})
  @parameters = parameters
end

Instance Method Details

#add_log_history(task) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/notifyme/log.rb', line 52

def add_log_history(task)
  now = Time.now.to_i
  if @@log_history[task.name].nil?
    @@log_history[task.name] = [now]
  else
    @@log_history[task.name] << now
  end
end

#can_log?(task) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
# File 'lib/notifyme/log.rb', line 42

def can_log?(task)
  history = @@log_history[task.name]
  return true if history.nil?

  checkpoint = LOG_FREQUENCE[history.size - 1] || LOG_FREQUENCE.last
  return true if Time.now.to_i - history.last > checkpoint 

  false
end

#clean_log_history!(task) ⇒ Object



61
62
63
# File 'lib/notifyme/log.rb', line 61

def clean_log_history!(task)
  @@log_history.delete(task.name) if @@log_history[task.name]
end

#fact(name) ⇒ Object



38
39
40
# File 'lib/notifyme/log.rb', line 38

def fact(name)
  Facter.fact(name).value
end