Commit 3c4898a5 authored by Alan Mitchell's avatar Alan Mitchell

Moved LOG_LEVEL to settings file.

And restricted count of inserted readings to be before the current time.
parent fc174ee7
################################################### ###################################################
# Django settings for BMON project. # # Django settings for BMON project. #
################################################### ###################################################
import logging
#----------------- Settings Specific to the Monitoring App ---------------------- #----------------- Settings Specific to the Monitoring App ----------------------
...@@ -56,6 +57,10 @@ PROJ_NAME = 'bmon' ...@@ -56,6 +57,10 @@ PROJ_NAME = 'bmon'
# further down in this settings file. # further down in this settings file.
STATIC_APP_NAME = 'bmon_static' 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 -------------- #------------ End of Settings Specific to the Monitoring App --------------
# The settings is the following section still need to be filled out, but these # The settings is the following section still need to be filled out, but these
......
...@@ -3,27 +3,19 @@ This file sets up logging. ...@@ -3,27 +3,19 @@ This file sets up logging.
''' '''
from os.path import dirname, join, realpath from os.path import dirname, join, realpath
import logging, logging.handlers import logging, logging.handlers
from django.conf import settings
APP_PATH = realpath(dirname(__file__)) APP_PATH = realpath(dirname(__file__))
# Log file for the application # Log file for the application
LOG_FILE = join(APP_PATH, 'logs', 'bms.log') 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' # create base logger for the application. Any other loggers named 'bms.XXXX'
# will inherit these settings. # will inherit these settings.
logger = logging.getLogger('bms') logger = logging.getLogger('bms')
# set the log level # set the log level
logger.setLevel(LOG_LEVEL) logger.setLevel(getattr(settings, 'LOG_LEVEL', logging.INFO))
# create a rotating file handler # create a rotating file handler
fh = logging.handlers.RotatingFileHandler(LOG_FILE, maxBytes=200000, backupCount=5) fh = logging.handlers.RotatingFileHandler(LOG_FILE, maxBytes=200000, backupCount=5)
......
...@@ -143,12 +143,13 @@ class BMSdata: ...@@ -143,12 +143,13 @@ class BMSdata:
def readingCount(self, startTime=0): def readingCount(self, startTime=0):
"""Returns the number of readings in the reading table inserted after the specified """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 rec_ct = 0
for id in self.sensor_ids: for id in self.sensor_ids:
try: 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] rec_ct += self.cursor.fetchone()[0]
except: except:
# not all tables are reading tables and may error out cause no 'ts' column # not all tables are reading tables and may error out cause no 'ts' column
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment