···10101111 def after_initialize
1212 if @enabled = !!@parent.config["sound"]
1313- if @parent.config["verbose"]
1414- puts "#{Time.now.to_f} - playing sound file " <<
1515- @parent.config["sound"]
1616- end
1313+ @parent.vputs "playing sound file " << @parent.config["sound"]
17141815 if `uname -s`.strip == "OpenBSD"
1916 @player = [ "aucat", "-i" ]
···2724 def log_pullup!(time)
2825 cmd = @player + [ @parent.config["sound"] ]
29263030- if @parent.config["debug"]
3131- puts "#{Time.now.to_f} - running " << cmd.inspect
3232- end
2727+ @parent.dputs "running " << cmd.inspect
33283429 system(*cmd)
3530 end
+5-10
lib/logger/fitbit.rb
···11111212 def after_initialize
1313 if @enabled = !!@parent.config["fitbit"]
1414- if @parent.config["verbose"]
1515- puts "#{Time.now.to_f} - enabling Fitbit logging module"
1616- end
1414+ @parent.vputs "enabling Fitbit logging module"
17151816 verify_keys
1917 end
···3533 begin
3634 h = JSON.parse(json)
3735 if (id = h["activityLog"]["activityId"].to_i) != 0
3838- if @parent.config["verbose"]
3939- puts "#{Time.now.to_f} - logged pullup on fitbit (id #{id})"
4040- end
3636+ @parent.vputs "logged pullup on fitbit (id #{id})"
4137 else
4238 raise "no activity id"
4339 end
44404541 rescue => e
4646- puts "#{Time.now.to_f} - error from fitbit (#{e.message}): " <<
4747- json.inspect
4242+ @parent.eputs "error from fitbit (#{e.message}): " << json.inspect
4843 end
4944 end
5045···7570 return res.body
7671 end
7772 rescue Timeout::Error => e
7878- puts "#{Time.now.to_f} - timed out talking to Fitbit: #{e.message}"
7373+ @parent.eputs "timed out talking to Fitbit: #{e.message}"
7974 rescue StandardError => e
8080- puts "#{Time.now.to_f} - error talking to Fitbit: #{e.message}"
7575+ @parent.eputs "error talking to Fitbit: #{e.message}"
8176 end
8277 end
8378
+2-6
lib/logger/textfile.rb
···8899 def after_initialize
1010 if @enabled = !!@parent.config["file"]
1111- if @parent.config["verbose"]
1212- puts "#{Time.now.to_f} - enabling plaintext logging module to " <<
1111+ @parent.vputs "enabling plaintext logging module to " <<
1312 @parent.config["file"]
1414- end
1513 end
1614 end
1715···2018 f.puts time.strftime("%Y-%m-%d %H:%M:%S")
2119 end
22202323- if @parent.config["verbose"]
2424- puts "#{Time.now.to_f} - logged to file #{@parent.config["file"]}"
2525- end
2121+ @parent.vputs "logged to file " << @parent.config["file"]
2622 end
2723end
+1-1
lib/loggerish.rb
···1414 end
15151616 def log_pullup!(time)
1717- puts "#{Time.now.to_f} - logged pullup"
1717+ @parent.aputs "logged pullup"
1818 end
1919end
+5-8
lib/sensor/phidget.rb
···2020 def main_loop
2121 begin
2222 Phidgets::InterfaceKit.new do |ifkit|
2323- if @parent.config["verbose"]
2424- puts "#{Time.now.to_f} - reading from Phidget #{ifkit.serial_number}"
2525- end
2323+ @parent.vputs "reading from Phidget #{ifkit.serial_number}"
26242725 ifkit.on_sensor_change do |device, input, value, obj|
2826 @cur_time = Time.now
···3533 end
36343735 rescue => e
3838- puts "#{Time.now.to_f} - exception in Phidget handler: #{e.message}"
3636+ @parent.eputs "exception in Phidget handler: #{e.message}"
3937 sleep 3
4038 retry
4139 end
···43414442 def cur_value=(value)
4543 if @parent.config["debug"]
4646- puts "#{@cur_time.to_f},#{value}"
4444+ # XXX: direct this somewhere so it doesn't get muxed with chatter
4545+ STDOUT.puts "#{@cur_time.to_f},#{value}"
4746 end
48474948 if @cur_time.to_i - @last_state_change.to_i > 10 && self.state != :idle
···8180 end
82818382 @state = state
8484- if @parent.config["verbose"]
8585- puts "#{@cur_time.to_f} - state is now #{state} (#{self.cur_value})"
8686- end
8383+ @parent.vputs "state is now #{state} (#{self.cur_value})"
87848885 if state == :pulled_up
8986 @parent.log_pullup!(@cur_time)
+21-2
pullup_counter.rb
···7676 begin
7777 logger.log_pullup!(time)
7878 rescue => e
7979- puts "#{Time.now.to_f} - error from #{logger.class} logger: " <<
8080- e.message
7979+ eputs "error from #{logger.class} logger: " << e.message
8180 end
8281 end
8382 end
8383+ end
8484+8585+ def aputs(str)
8686+ STDOUT.puts Time.now.strftime("%Y-%m-%d %H:%M:%S.%L") << " - #{str}"
8787+ end
8888+8989+ def dputs(str)
9090+ if @config["debug"]
9191+ STDOUT.puts Time.now.strftime("%Y-%m-%d %H:%M:%S.%L") << " - #{str}"
9292+ end
9393+ end
9494+9595+ def vputs(str)
9696+ if @config["verbose"] || @config["debug"]
9797+ STDOUT.puts Time.now.strftime("%Y-%m-%d %H:%M:%S.%L") << " - #{str}"
9898+ end
9999+ end
100100+101101+ def eputs(str)
102102+ STDERR.puts Time.now.strftime("%Y-%m-%d %H:%M:%S.%L") << " - #{str}"
84103 end
85104end
86105