Add basic logging.
This commit is contained in:
parent
ebd237d9d3
commit
1a5df46eca
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
/logs/*
|
||||
config.ini
|
||||
*.db
|
||||
*.log
|
||||
|
|
|
@ -17,3 +17,4 @@ kiss_port = 8001
|
|||
|
||||
# Development settings (not operational yet)
|
||||
mycall = W1CDN-15
|
||||
log_path = aprs_api.log
|
||||
|
|
|
@ -6,6 +6,7 @@ import json
|
|||
import aprslib
|
||||
import configparser
|
||||
import time
|
||||
import logging
|
||||
|
||||
def read_config():
|
||||
config = configparser.ConfigParser()
|
||||
|
@ -25,6 +26,8 @@ def main():
|
|||
# KISS_HOST = os.environ.get("KISS_HOST", "192.168.0.30")
|
||||
# KISS_PORT = os.environ.get("KISS_PORT", "8001")
|
||||
|
||||
logging.basicConfig(filename=config['Settings']['log_path'], encoding='utf-8', level=logging.DEBUG)
|
||||
logging.debug('kiss_and_db.py running')
|
||||
|
||||
ki = aprs.TCPKISS(host=config['Settings']['kiss_host'], port=int(config['Settings']['kiss_port']))
|
||||
ki.start()
|
||||
|
@ -66,6 +69,7 @@ def main():
|
|||
try:
|
||||
# Insert data
|
||||
sql = "INSERT INTO frames ("+attrib_names+") VALUES ("+attrib_values+")"
|
||||
logging.debug(sql)
|
||||
conn.execute(sql, list(a.values()))
|
||||
|
||||
# TODO update stations table here
|
||||
|
@ -81,7 +85,8 @@ def main():
|
|||
VALUES("+station_update+") \
|
||||
ON CONFLICT([from]) \
|
||||
DO UPDATE SET count = count + 1;"
|
||||
print(query3)
|
||||
#print(query3)
|
||||
logging.debug(query3)
|
||||
# Insert/update data
|
||||
conn.execute(query3)
|
||||
|
||||
|
@ -94,9 +99,11 @@ def main():
|
|||
#conn.execute("DELETE FROM frames WHERE created < DATETIME('now', '"+config['Settings']['keep_time']+"')")
|
||||
#conn.commit()
|
||||
except:
|
||||
print("Error with SQLite!")
|
||||
#print("Error with SQLite!")
|
||||
logging.error("Error with SQLite!")
|
||||
except:
|
||||
print("Frame could not be parsed.")
|
||||
#print("Frame could not be parsed.")
|
||||
logging.error("Frame could not be parsed.")
|
||||
|
||||
|
||||
conn.close()
|
||||
|
|
Loading…
Reference in New Issue
Block a user