From 3c4898a52c1dff00756dbedd8502e99fa2fb9b85 Mon Sep 17 00:00:00 2001 From: Alan Mitchell Date: Sat, 31 Jan 2015 14:26:48 -0900 Subject: [PATCH] Moved LOG_LEVEL to settings file. And restricted count of inserted readings to be before the current time. --- bmon/settings_example.py | 5 +++++ bmsapp/logging_setup.py | 12 ++---------- bmsapp/readingdb/bmsdata.py | 5 +++-- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/bmon/settings_example.py b/bmon/settings_example.py index d35eb0d..0c3f7ea 100644 --- a/bmon/settings_example.py +++ b/bmon/settings_example.py @@ -1,6 +1,7 @@ ################################################### # Django settings for BMON project. # ################################################### +import logging #----------------- Settings Specific to the Monitoring App ---------------------- @@ -56,6 +57,10 @@ PROJ_NAME = 'bmon' # further down in this settings file. STATIC_APP_NAME = 'bmon_static' +# This controls what messages will actually get logged +# Levels in order from least to greatest severity are: DEBUG, INFO, WARNING, ERROR, CRITICAL +LOG_LEVEL = logging.INFO + #------------ End of Settings Specific to the Monitoring App -------------- # The settings is the following section still need to be filled out, but these diff --git a/bmsapp/logging_setup.py b/bmsapp/logging_setup.py index dbf526c..1e99539 100644 --- a/bmsapp/logging_setup.py +++ b/bmsapp/logging_setup.py @@ -3,27 +3,19 @@ This file sets up logging. ''' from os.path import dirname, join, realpath import logging, logging.handlers +from django.conf import settings APP_PATH = realpath(dirname(__file__)) # Log file for the application LOG_FILE = join(APP_PATH, 'logs', 'bms.log') -# *** This controls what messages will actually get logged -# Levels in order from least to greatest severity are: DEBUG, INFO, WARNING, ERROR, CRITICAL -# Methods to call that automatically set appropriate level are: debug(), info(), warning(), error(), -# exception(), and critical(). If 'exception()' is called, an exception traceback is automatically -# added to the log message (only call from within an exception handler). -LOG_LEVEL = logging.INFO - -# ---- - # create base logger for the application. Any other loggers named 'bms.XXXX' # will inherit these settings. logger = logging.getLogger('bms') # set the log level -logger.setLevel(LOG_LEVEL) +logger.setLevel(getattr(settings, 'LOG_LEVEL', logging.INFO)) # create a rotating file handler fh = logging.handlers.RotatingFileHandler(LOG_FILE, maxBytes=200000, backupCount=5) diff --git a/bmsapp/readingdb/bmsdata.py b/bmsapp/readingdb/bmsdata.py index 9a8268c..539130a 100644 --- a/bmsapp/readingdb/bmsdata.py +++ b/bmsapp/readingdb/bmsdata.py @@ -143,12 +143,13 @@ class BMSdata: def readingCount(self, startTime=0): """Returns the number of readings in the reading table inserted after the specified - 'startTime' (Unix seconds). + 'startTime' (Unix seconds) and before now (in case erroneously timestamped readings + are in the file). """ rec_ct = 0 for id in self.sensor_ids: try: - self.cursor.execute('SELECT COUNT(*) FROM [%s] WHERE ts > ?' % id, (startTime,)) + self.cursor.execute('SELECT COUNT(*) FROM [%s] WHERE ts > ? and ts < ?' % id, (startTime, time.time())) rec_ct += self.cursor.fetchone()[0] except: # not all tables are reading tables and may error out cause no 'ts' column -- GitLab