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