diff --git a/bmon/settings_example.py b/bmon/settings_example.py index d35eb0d691a8b624ddf3e4300ed27ceb6217b2d6..0c3f7ea2d78c02735c126083a794e675389e1ee2 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 dbf526cd71cc4bb3d79d699ae42e991bdaef628a..1e99539dc3b2673db67618f472370ecba22627e8 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 9a8268cf669cf6a80a2efcea5c00c8ad85911f47..539130a255e780de0262a3a064968bc81727bb48 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