Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
energy
bmon
Commits
3c4898a5
Commit
3c4898a5
authored
Jan 31, 2015
by
Alan Mitchell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved LOG_LEVEL to settings file.
And restricted count of inserted readings to be before the current time.
parent
fc174ee7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
12 deletions
+10
-12
bmon/settings_example.py
bmon/settings_example.py
+5
-0
bmsapp/logging_setup.py
bmsapp/logging_setup.py
+2
-10
bmsapp/readingdb/bmsdata.py
bmsapp/readingdb/bmsdata.py
+3
-2
No files found.
bmon/settings_example.py
View file @
3c4898a5
###################################################
# 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
...
...
bmsapp/logging_setup.py
View file @
3c4898a5
...
...
@@ -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
)
...
...
bmsapp/readingdb/bmsdata.py
View file @
3c4898a5
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment