26 lines
417 B
Ruby
26 lines
417 B
Ruby
# frozen_string_literal: true
|
|
|
|
class ActivityLogger
|
|
|
|
@@loggers = Hash.new { |hash, key| hash[key] = [] }
|
|
|
|
def self.register(id, sse)
|
|
@@loggers[id] << sse
|
|
end
|
|
|
|
def self.unregister(id, sse)
|
|
@@loggers[id].delete(sse)
|
|
end
|
|
|
|
def self.log(id, event)
|
|
@@loggers[id].each do |logger|
|
|
logger.write event
|
|
rescue
|
|
puts 'rescued'
|
|
end
|
|
end
|
|
|
|
def self.reset
|
|
@@loggers.clear
|
|
end
|
|
end
|