A program to read a Phidget IR sensor and log pull-ups with Fitbit's API
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

mutex around logging to avoid trampling over other logging calls

+13 -4
+13 -4
pullup_counter.rb
··· 26 26 27 27 def initialize 28 28 @config = ConfigHash.new 29 + @semaphore = Mutex.new 29 30 30 31 # add in options from each logger 31 32 @loggers = [] ··· 83 84 end 84 85 85 86 def aputs(str) 86 - STDOUT.puts Time.now.strftime("%Y-%m-%d %H:%M:%S.%L") << " - #{str}" 87 + @semaphore.synchronize do 88 + STDOUT.puts Time.now.strftime("%Y-%m-%d %H:%M:%S.%L") << " - #{str}" 89 + end 87 90 end 88 91 89 92 def dputs(str) 90 93 if @config["debug"] 91 - STDOUT.puts Time.now.strftime("%Y-%m-%d %H:%M:%S.%L") << " - #{str}" 94 + @semaphore.synchronize do 95 + STDOUT.puts Time.now.strftime("%Y-%m-%d %H:%M:%S.%L") << " - #{str}" 96 + end 92 97 end 93 98 end 94 99 95 100 def vputs(str) 96 101 if @config["verbose"] || @config["debug"] 97 - STDOUT.puts Time.now.strftime("%Y-%m-%d %H:%M:%S.%L") << " - #{str}" 102 + @semaphore.synchronize do 103 + STDOUT.puts Time.now.strftime("%Y-%m-%d %H:%M:%S.%L") << " - #{str}" 104 + end 98 105 end 99 106 end 100 107 101 108 def eputs(str) 102 - STDERR.puts Time.now.strftime("%Y-%m-%d %H:%M:%S.%L") << " - #{str}" 109 + @semaphore.synchronize do 110 + STDERR.puts Time.now.strftime("%Y-%m-%d %H:%M:%S.%L") << " - #{str}" 111 + end 103 112 end 104 113 end 105 114