Skip to content

Commit

Permalink
small cleanup of logging functions
Browse files Browse the repository at this point in the history
  • Loading branch information
1n5aN1aC committed Dec 15, 2015
1 parent 0731fcd commit 9fd510e
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions framework/update_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def update_archive(self):
Out_Wind_Max=now.Out_Wind_Max,
Out_Rain_Minute=rain_amount,
Now_Feel=now.Now_Feel)
logging.getLogger("thread").info(" Sensor Data Archived.")
logging.getLogger("thread-archive").info(" Sensor data archived.")

#
# This deletes old rain data from the 'rain' table. This data is no longer needed,
Expand All @@ -57,4 +57,4 @@ def update_clean_old(self):
if (datetime.datetime.now() - rain.time) > datetime.timedelta(days = how_many_days_of_rain_data_to_keep):
rain.destroySelf()
number_cleaned = number_cleaned + 1
logging.getLogger("thread").info(" Rain Table Cleaned. (" + str(number_cleaned) + " entries purged in " + str((time.time() - start)*1000) + "ms)")
logging.getLogger("thread-clean").info(" Rain table cleaned. (" + str(number_cleaned) + " entries purged in " + str((time.time() - start)*1000) + "ms)")
2 changes: 1 addition & 1 deletion framework/update_feels_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ def update_feels_like(self):
now = Table_Now.get(1)
now.Now_URL = NOW_URL
now.Now_Feel = NOW_Feel
logging.getLogger("thread").info(" Updated Feels Like Data.")
logging.getLogger("thread-feels").info(" Updated feels like info.")
2 changes: 1 addition & 1 deletion framework/update_rain_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ def update_rain_compile(self):
now.Out_Rain_Last_24h = rain_24h
now.Out_Rain_Today = rain_today

logging.getLogger("thread").info(" Compiled Rain Data.")
logging.getLogger("thread-rain_compile").info(" Compiled rain pulse data.")
2 changes: 1 addition & 1 deletion framework/update_sensor_rain.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ def update_sensor_rain(self):
now = Table_Now.get(1)
now.sync()
now.Out_Rain_Since_Reset = now.Out_Rain_Since_Reset + rainTipAmount
logging.getLogger("thread").info(" Caused A Fake Rain Pulse.")
logging.getLogger("thread-rain_fake").info(" Caused a fake rain pulse.")
18 changes: 9 additions & 9 deletions framework/update_sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ def run(self):
time.sleep(1)

#Then tell deamon threads to die, and reap their souls
logging.getLogger("thread").info(" Telling sensor threads to die...")
logging.getLogger("thread-sensors").info(" Telling sensor threads to die...")
for thread in sensor_threads:
thread.stop()
for thread in sensor_threads:
thread.join(how_long_to_wait_before_killing_deamons)
logging.getLogger("thread").debug(" Sensor threads have been killed!")
logging.getLogger("thread-sensors").debug(" Sensor threads have been killed!")

# Thread for updating the outside T/H sensor
class update_outside(stoppable_thread):
Expand All @@ -58,7 +58,7 @@ def run(self):
now.Out_Temp = sum(OUT_Temp_Q['Q']) / float(len(OUT_Temp_Q['Q']))
now.Out_Humid = sum(OUT_Humid_Q['Q']) / float(len(OUT_Humid_Q['Q']))

logging.getLogger("sensor").debug(" Updated Outside Sensor Data.")
logging.getLogger("sensor").debug(" Updated outside sensor data.")
time.sleep(how_often_to_check_temp)

# Thread for updating the attic T/H sensor
Expand All @@ -73,7 +73,7 @@ def run(self):
now.Attic_Temp = sum(ATT_Temp_Q['Q']) / float(len(ATT_Temp_Q['Q']))
now.Attic_Humid = sum(ATT_Humid_Q['Q']) / float(len(ATT_Humid_Q['Q']))

logging.getLogger("sensor").debug(" Updated Attic Sensor Data.")
logging.getLogger("sensor").debug(" Updated attic sensor data.")
time.sleep(how_often_to_check_temp)

# Thread for updating the inside T/H sensor
Expand All @@ -88,7 +88,7 @@ def run(self):
now.In_Temp = sum(IN_Temp_Q['Q']) / float(len(IN_Temp_Q['Q']))
now.In_Humid = sum(IN_Humid_Q['Q']) / float(len(IN_Humid_Q['Q']))

logging.getLogger("sensor").debug(" Updated Inside Sensor Data.")
logging.getLogger("sensor").debug(" Updated inside sensor data.")
time.sleep(how_often_to_check_temp)

# Thread for updating the wind sensor
Expand All @@ -104,7 +104,7 @@ def run(self):
now.Out_Wind_Avg = sum(Wind_Avg_Q['Q']) / float(len(Wind_Avg_Q['Q']))
now.Out_Wind_Max = max(Wind_Max_Q['Q'])

logging.getLogger("sensor").debug(" Updated Wind Data.")
logging.getLogger("sensor").debug(" Updated wind data.")
time.sleep(how_often_to_check_wind)

# Thread for updating the system stats
Expand All @@ -115,7 +115,7 @@ def run(self):
now.System_CPU = sensors.read_cpu_usage()
now.System_RAM = sensors.read_ram_usage()

logging.getLogger("sensor").debug(" Updated SYSTEM Data.")
logging.getLogger("sensor").debug(" Updated SYSTEM data.")
time.sleep(how_often_to_check_system)

# This takes a dequeue, and a reading, and adds that reading to the dequeue.
Expand All @@ -126,7 +126,7 @@ def add_reading_to_dequeue(dequeue, new_reading):
(dequeue)['Fails'] = 0
elif dequeue['Fails'] < failed_readings_before_error:
dequeue['Fails'] = dequeue['Fails'] + 1
logging.getLogger("thread_sensors").warning(" Failed to update Sensor " + dequeue['Name'] + ".")
logging.getLogger("thread_sensors").warning(" Failed to update sensor " + dequeue['Name'] + ".")
else:
dequeue['Q'].append(0)
logging.getLogger("thread_sensors").error(" Sensor has Failed: " + dequeue['Name'] + "!!")
logging.getLogger("thread_sensors").error(" Sensor has failed: " + dequeue['Name'] + "!!")
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="43200">
<!-- <meta http-equiv="refresh" content="12"> -->
<link href='https://fonts.googleapis.com/css?family=Play:700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="/js/jquery-ui-1.11.4/jquery-ui.min.css">
<link rel="stylesheet" href="/js/jquery-ui-1.11.4/themes/eggplant/theme.css">
Expand Down
6 changes: 3 additions & 3 deletions thread_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!python
import time, sys, signal
import threading, logging
import time, sys, signal, logging
from framework import update_sensors
from framework import update_sensor_rain
from framework import update_rain_compile
Expand All @@ -27,14 +26,15 @@

# Signal handler to properly close all DB handles
def signal_handler(signal, frame):
print('Closing...')
logging.getLogger("core").warning(" Shutting down...")
for thread in threads:
thread.stop()
time.sleep(settings.how_long_to_wait_before_killing_threads)
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)

# Create the threads
logging.getLogger("core").info(" Launching the threads...")
threads.append( update_sensors.thread_sensors() )
threads.append( update_sensor_rain.thread_sensor_rain() )
threads.append( update_rain_compile.thread_rain_compile() )
Expand Down

0 comments on commit 9fd510e

Please sign in to comment.