app/models/extface/driver.rb in extface-0.2.2 vs app/models/extface/driver.rb in extface-0.2.3

- old
+ new

@@ -37,17 +37,23 @@ def handle(buffer) $stdout.puts "Extface:#{device.uuid} PUSH #{buffer}" return buffer.length # return number of bytes processed end + def pre_handle(buffer) + logger.debug "<-- #{buffer.bytes.map{ |b| '%02X' % b }.join(' ')}" if development? + handle(buffer) + end + def push(buffer) if @job Timeout.timeout(Extface.device_timeout) do Extface.redis_block do |r| r.subscribe(@job.id) do |on| #blocking until delivered on.subscribe do |channel, subscriptions| @job.rpush buffer + logger.debug "--> #{buffer.bytes.map{ |b| '%02X' % b }.join(' ')}" if development? end on.message do |event, data| r.unsubscribe @job.connected! end @@ -96,8 +102,20 @@ end private def buffer_key "#{device.uuid}:#{self.id}" + end + + def logger + @logger ||= begin + dir = "#{Rails.root}/log/extface/#{device.id}" + FileUtils.mkdir_p(dir) unless File.directory?(dir) + Logger.new("#{dir}/#{self.class.name.demodulize.underscore}.log", 'daily') + end + end + + def development? + self.class::DEVELOPMENT end end end