mirror of
https://github.com/brmlab/brmdoor_libnfc.git
synced 2025-06-07 16:14:01 +02:00
Logfile and loglevel added
This commit is contained in:
parent
02c9ba3d58
commit
b3d03b1f69
2 changed files with 24 additions and 2 deletions
|
@ -1,5 +1,9 @@
|
|||
# auth_db_filename - sqlite filename of authorized UIDs, create with create_authenticator_db.py
|
||||
# lock_opened_secs - how long lock should be held open in seconds, default 5
|
||||
# log_file - logs read UIDs and when was lock opened, use - for stderr
|
||||
# log_level - minimum log level - one of debug, info, warn, error, fatal, default info
|
||||
[brmdoor]
|
||||
auth_db_filename = test_uids_db.sqlite
|
||||
#lock_opened_secs = 5
|
||||
log_file = -
|
||||
#log_level = info
|
||||
|
|
|
@ -26,6 +26,7 @@ class BrmdoorConfig(object):
|
|||
|
||||
_defaults = {
|
||||
"lock_opened_secs": "5",
|
||||
"log_level": "info"
|
||||
}
|
||||
|
||||
def __init__(self, filename):
|
||||
|
@ -40,7 +41,20 @@ class BrmdoorConfig(object):
|
|||
|
||||
self.authDbFilename = self.config.get("brmdoor", "auth_db_filename")
|
||||
self.lockOpenedSecs = self.config.getint("brmdoor", "lock_opened_secs")
|
||||
self.logFile = self.config.get("brmdoor", "log_file")
|
||||
self.logLevel = self.convertLoglevel(self.config.get("brmdoor", "log_level"))
|
||||
|
||||
def convertLoglevel(self, levelString):
|
||||
"""Converts string 'debug', 'info', etc. into corresponding
|
||||
logging.XXX value which is returned.
|
||||
|
||||
@raises ValueError if the level is undefined
|
||||
"""
|
||||
try:
|
||||
return getattr(logging, levelString.upper())
|
||||
except AttributeError:
|
||||
raise BrmdoorConfigError("No such loglevel - %s" % levelString)
|
||||
|
||||
class NfcThread(threading.Thread):
|
||||
"""Thread reading data from NFC reader"""
|
||||
|
||||
|
@ -107,8 +121,12 @@ if __name__ == "__main__":
|
|||
|
||||
config = BrmdoorConfig(sys.argv[1])
|
||||
|
||||
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG,
|
||||
format="%(asctime)s %(levelname)s %(message)s [%(pathname)s:%(lineno)d]")
|
||||
if config.logFile == "-":
|
||||
logging.basicConfig(stream=sys.stderr, level=config.logLevel,
|
||||
format="%(asctime)s %(levelname)s %(message)s [%(pathname)s:%(lineno)d]")
|
||||
else:
|
||||
logging.basicConfig(filename=config.logFile, level=config.logLevel,
|
||||
format="%(asctime)s %(levelname)s %(message)s [%(pathname)s:%(lineno)d]")
|
||||
|
||||
uidQueue = Queue.Queue(1)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue