Skip to content

Commit

Permalink
better exception logging
Browse files Browse the repository at this point in the history
  • Loading branch information
vzaliva committed Mar 15, 2013
1 parent 617bd8a commit 19d7dee
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 33 deletions.
10 changes: 5 additions & 5 deletions cosm_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def read_watermark(watermark_fname):
return cfg["maxtime"]
finally:
f.close()
except:
log.warning("Error reading watermark file %s. Assuming 0" % watermark_fname)
except Exception, ex:
log.warning("Error reading watermark file %s. Assuming 0. %ex" % (watermark_fname,ex))
return 0

def write_watermark(watermark_fname,w):
Expand Down Expand Up @@ -109,9 +109,9 @@ def main():
log = logging.getLogger('default')

try:
cfg=read_config(cfg_fname)
except:
log.error("Error reading config file %s" % cfg_fname)
cfg = read_config(cfg_fname)
except Exception, ex:
log.error("Error reading config file %s" % ex)
sys.exit(1)

feed = cfg["feed"]
Expand Down
15 changes: 9 additions & 6 deletions data_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ def main():

try:
cfg = read_config(cfg_fname)
except:
log.error("Error reading config file %s" % cfg_fname)
except Exception, ex:
log.error("Error reading config file %s" % ex)
sys.exit(1)

print 'Using serial port %s' % port
Expand Down Expand Up @@ -166,16 +166,19 @@ def main():
time.time(), pkt.address, radc0, radc1, temp_C, battery_V*1000.0)

if not debug_mode:
data_file.write(csv_report)
data_file.flush()
try:
data_file.write(csv_report)
data_file.flush()
except IOError, ex:
log.error("Error writing CSV file: %s" % ex)

except IndexError, e:
# I get this from pkt.get_adc() when packet is broken
log.error('Broken XBee packet: "{0}"'.format(pkt))


except serial.SerialException,e:
print e
except serial.SerialException, ex:
log.debug("Serial error %s" % ex)

if __name__ == '__main__':
main()
24 changes: 12 additions & 12 deletions radiothermostat_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ def main():
log = logging.getLogger('default')

try:
cfg=read_config(cfg_fname)
except:
log.error("Error reading config file %s" % cfg_fname)
cfg = read_config(cfg_fname)
except Exception, ex:
log.error("Error reading config file %s" % ex)
sys.exit(1)

ip = cfg["IP"]
Expand Down Expand Up @@ -156,13 +156,13 @@ def main():
else:
s+=" HVAC is cooling."
log.info(s)
except:
log.error("Error fetching data from API" + str(sys.exc_info()[0]))
except Exception, ex:
log.error("Error fetching data from API: %s" % ex)
sys.exit(1)
finally:
f.close()
except:
log.error("Error fetching connecting to API: " + str(sys.exc_info()[0]))
except Exception, ex:
log.error("Error fetching connecting to API: %s" %ex)
next

csv_report = '{0},{1:.3f},{2},{3}\n'.format(local_time,temp_c,tstate,fstate)
Expand All @@ -174,9 +174,9 @@ def main():
try:
data_file.write(csv_report)
data_file.flush()
except:
except IOError, ex:
# Error writing CSV is fatal
log.error("Error writing cfg file")
log.error("Error writing CSV file: %s" % ex)
sys.exit(1)

# Send to COSM
Expand All @@ -190,9 +190,9 @@ def main():
try:
cosm_report =string.join([ts,str(data[ds])],",") + "\r\n"
cosm.submit_datapoints(cosm_feed,ds,cosm_key,cosm_report)
except:
# Error sending to cosm is non-fatal, but logged anyway
log.error("Error sending to COSM datastream %s" % ds)
except Exception, ex:
# Error sending to COSM is non-fatal, but logged
log.warning("Error sending to COSM datastream %s. %s" % (ds,ex))

if sleep_time>0:
time.sleep(sleep_time)
Expand Down
20 changes: 10 additions & 10 deletions wu_temp_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ def main():
log = logging.getLogger('default')

try:
cfg=read_config(cfg_fname)
except:
log.error("Error reading config file %s" % cfg_fname)
cfg = read_config(cfg_fname)
except Exception, ex:
log.error("Error reading config file %s" % ex)
sys.exit(1)

key = cfg["key"]
Expand All @@ -147,12 +147,12 @@ def main():
observation_time = int(parsed_json['current_observation']['observation_epoch'])
temp_c = parsed_json['current_observation']['temp_c']
log.info("Current temperature is: %s" % temp_c)
except:
log.error("Error fetching data from API")
except Exception, ex:
log.error("Error fetching data from API: %s" %ex)
sys.exit(1)
finally:
f.close()
except:
except Exception, ex:
log.error("Error fetching connecting to API")
next

Expand All @@ -165,19 +165,19 @@ def main():
try:
data_file.write(csv_report)
data_file.flush()
except:
except IOError, ex:
# Error writing CSV is fatal
log.error("Error writing cfg file")
log.error("Error writing CSV file: %s" % ex)
sys.exit(1)
# Send to COSM
if cfg.has_key("cosm"):
try:
ts = datetime.datetime.utcfromtimestamp(int(local_time)).isoformat('T')+"Z"
cosm_report =string.join([ts,str(temp_c)],",") + "\r\n"
cosm.submit_datapoints(cosm_feed,cosm_datastream,cosm_key,cosm_report)
except:
except Exception, ex:
# Error sending to cosm is non-fatal, but logged anyway
log.error("Error sending to COSM")
log.error("Error sending to COSM: %s" % ex )

if sleep_time>0:
time.sleep(sleep_time)
Expand Down

0 comments on commit 19d7dee

Please sign in to comment.