Changing logger.DEBUG to logger.INFO or logger.ERROR, by context.

This commit is contained in:
Marat Fayzullin 2024-06-19 23:20:37 -04:00
parent 78db155db4
commit 3d97370488
6 changed files with 65 additions and 68 deletions

View File

@ -201,7 +201,7 @@ class AircraftManager(object):
# If no such ID yet...
if id not in self.aircraft:
logger.debug("Adding %s" % id)
logger.info("Adding %s" % id)
# Create a new record
item = self.aircraft[id] = data.copy()
updated = True
@ -257,7 +257,7 @@ class AircraftManager(object):
with self.lock:
too_old = [x for x in self.aircraft.keys() if self.aircraft[x]["ttl"] < now]
if too_old:
logger.debug("Following aircraft have become stale: {0}".format(too_old))
logger.info("Following aircraft have become stale: {0}".format(too_old))
for id in too_old:
self._removeFromMap(id)
del self.aircraft[id]
@ -278,10 +278,10 @@ class AircraftManager(object):
def _merge(self, id1, id2):
if id1 not in self.aircraft:
if id2 in self.aircraft:
logger.debug("Linking %s to %s" % (id1, id2))
logger.info("Linking %s to %s" % (id1, id2))
self.aircraft[id1] = self.aircraft[id2]
elif id2 not in self.aircraft:
logger.debug("Linking %s to %s" % (id2, id1))
logger.info("Linking %s to %s" % (id2, id1))
self.aircraft[id2] = self.aircraft[id1]
else:
item1 = self.aircraft[id1]
@ -292,7 +292,7 @@ class AircraftManager(object):
item1, item2 = item2, item1
id1, id2 = id2, id1
# Update older data with newer data
logger.debug("Merging %s into %s" % (id2, id1))
logger.info("Merging %s into %s" % (id2, id1))
item2.update(item1)
self.aircraft[id1] = item2
# Change ID2 color to ID1
@ -308,7 +308,7 @@ class AircraftManager(object):
if "lat" in item and "lon" in item:
Map.getSharedInstance().removeLocation(id)
except Exception as exptn:
logger.debug("Exception removing aircraft %s: %s" % (id, str(exptn)))
logger.error("Exception removing aircraft %s: %s" % (id, str(exptn)))
#

View File

@ -14,7 +14,6 @@ import time
import math
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
#
# Maximal distance on Earth surface (kilometers)
@ -99,26 +98,26 @@ class EIBI(object):
# Save schedule to a given JSON file
def saveSchedule(self, file: str, schedule):
logger.debug("Saving {0} schedule entries to '{1}'...".format(len(schedule), file))
logger.info("Saving {0} schedule entries to '{1}'...".format(len(schedule), file))
try:
with open(file, "w") as f:
json.dump(schedule, f, indent=2)
f.close()
except Exception as e:
logger.debug("saveSchedule() exception: {0}".format(e))
logger.error("saveSchedule() exception: {0}".format(e))
# Load schedule from a given JSON file
def loadSchedule(self, file: str):
logger.debug("Loading schedule from '{0}'...".format(file))
logger.info("Loading schedule from '{0}'...".format(file))
try:
with open(file, "r") as f:
result = json.load(f)
f.close()
except Exception as e:
logger.debug("loadSchedule() exception: {0}".format(e))
logger.error("loadSchedule() exception: {0}".format(e))
result = []
# Done
logger.debug("Loaded {0} entries from '{1}'...".format(len(result), file))
logger.info("Loaded {0} entries from '{1}'...".format(len(result), file))
return result
# Find all current broadcasts for a given source
@ -210,7 +209,7 @@ class EIBI(object):
result[name]["ttl"] = max(ttl, result[name]["ttl"]);
except Exception as e:
logger.debug("currentTransmitters() exception: {0}".format(e))
logger.error("currentTransmitters() exception: {0}".format(e))
# Done
return result
@ -238,7 +237,7 @@ class EIBI(object):
# No result yet
result = {}
logger.debug("Creating bookmarks for {0}-{1}kHz within {2}km...".format(f1//1000, f2//1000, rangeKm))
logger.info("Creating bookmarks for {0}-{1}kHz within {2}km...".format(f1//1000, f2//1000, rangeKm))
# Search for current entries
with self.lock:
@ -291,9 +290,9 @@ class EIBI(object):
result[f] = ( entry, dist, duration )
except Exception as e:
logger.debug("currentBookmarks() exception: {0}".format(e))
logger.error("currentBookmarks() exception: {0}".format(e))
logger.debug("Created {0} bookmarks for {1}-{2}kHz within {3}km.".format(len(result), f1//1000, f2//1000, rangeKm))
logger.info("Created {0} bookmarks for {1}-{2}kHz within {3}km.".format(len(result), f1//1000, f2//1000, rangeKm))
# Return bookmarks for all found entries
return [ Bookmark({
@ -361,7 +360,7 @@ class EIBI(object):
# Fetch and parse CSV file
result = []
try:
logger.debug("Scraping '{0}'...".format(url))
logger.info("Scraping '{0}'...".format(url))
for line in urllib.request.urlopen(url).readlines():
# Convert read bytes to a string
line = line.decode('cp1252').rstrip()
@ -437,7 +436,7 @@ class EIBI(object):
})
except Exception as e:
logger.debug("loadFromWeb() exception: {0}".format(e))
logger.error("loadFromWeb() exception: {0}".format(e))
# Done
return result

View File

@ -76,13 +76,13 @@ class GpsUpdater(object):
# Stop the main thread
def stopThread(self):
if self.thread is not None:
logger.debug("Stopping GPS updater thread.")
logger.info("Stopping GPS updater thread.")
self.event.set()
self.thread.join()
# This is the actual thread function
def _refreshThread(self):
logger.debug("Starting GPS updater thread...")
logger.info("Starting GPS updater thread...")
pm = Config.get()
gps = GpsdClient()
# Main loop
@ -91,7 +91,7 @@ class GpsUpdater(object):
pos = gps.getPosition()
pos = pos.position() if pos else None
if pos:
logger.debug("New position is {0}, {1}".format(pos[0], pos[1]))
logger.info("New position is {0}, {1}".format(pos[0], pos[1]))
pm["receiver_gps"] = { "lat": pos[0], "lon": pos[1] }
except Exception as e:
logger.error("Failed to get GPS position: " + str(e))
@ -124,18 +124,18 @@ class GpsdClient(object):
# Connect to GPSD at given address and port
def connect(self, host: str = "127.0.0.1", port: int = 2947):
self.disconnect()
logger.debug("Connecting to GPSD at {}:{}".format(host, port))
logger.info("Connecting to GPSD at {}:{}".format(host, port))
try:
# Connect socket
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.connect((host, port))
self.stream = self.socket.makefile(mode="rw")
# Perform initial exchange
logger.debug("Waiting for welcome message...")
logger.info("Waiting for welcome message...")
welcome = json.loads(self.stream.readline())
if "class" not in welcome or welcome["class"] != "VERSION":
raise Exception("Unexpected data received as welcome. Not a GPSD v3 server?")
logger.debug("Enabling GPS...")
logger.info("Enabling GPS...")
self.stream.write('?WATCH={"enable":true}\n')
self.stream.flush()
# Get initial state
@ -159,7 +159,7 @@ class GpsdClient(object):
# Get current GPS position
def getPosition(self):
if self.stream:
logger.debug("Polling GPSD for position...")
logger.info("Polling GPSD for position...")
try:
# Poll GPSD
self.stream.write("?POLL;\n")

View File

@ -17,7 +17,6 @@ import os
import time
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
class MyJSONEncoder(JSONEncoder):
@ -99,13 +98,13 @@ class Markers(object):
# Stop the main thread
def stopThread(self):
if self.thread is not None:
logger.debug("Stopping marker database thread.")
logger.info("Stopping marker database thread.")
self.event.set()
self.thread.join()
# This is the actual thread function
def _refreshThread(self):
logger.debug("Starting marker database thread...")
logger.info("Starting marker database thread...")
# No markers yet
self.markers = {}
@ -138,7 +137,7 @@ class Markers(object):
self.remarkers = self.loadRepeaters()
# Update map with markers
logger.debug("Updating map...")
logger.info("Updating map...")
self.updateMap(self.markers)
self.updateMap(self.rxmarkers)
self.updateMap(self.txmarkers)
@ -155,7 +154,7 @@ class Markers(object):
break
# Load new transmitters schedule from the EIBI
logger.debug("Refreshing transmitters schedule..")
logger.info("Refreshing transmitters schedule..")
tx = self.loadCurrentTransmitters()
# Check if we need to exit
@ -188,7 +187,7 @@ class Markers(object):
# Update cached receivers data
if time.time() - ts >= self.refreshPeriod:
logger.debug("Refreshing receivers database...")
logger.info("Refreshing receivers database...")
rx = self.updateCache()
ts = os.path.getmtime(file)
if rx:
@ -207,29 +206,29 @@ class Markers(object):
rx = None
# Done with the thread
logger.debug("Stopped marker database thread.")
logger.info("Stopped marker database thread.")
self.thread = None
# Save markers to a given file
def saveMarkers(self, file: str, markers):
logger.debug("Saving {0} markers to '{1}'...".format(len(markers), file))
logger.info("Saving {0} markers to '{1}'...".format(len(markers), file))
try:
with open(file, "w") as f:
json.dump(markers, f, cls=MyJSONEncoder, indent=2)
f.close()
except Exception as e:
logger.debug("saveMarkers() exception: {0}".format(e))
logger.error("saveMarkers() exception: {0}".format(e))
# Load markers from a given file
def loadMarkers(self, file: str):
logger.debug("Loading markers from '{0}'...".format(file))
logger.info("Loading markers from '{0}'...".format(file))
# Load markers list from JSON file
try:
with open(file, "r") as f:
db = json.load(f)
f.close()
except Exception as e:
logger.debug("loadMarkers() exception: {0}".format(e))
logger.error("loadMarkers() exception: {0}".format(e))
return
# Process markers list
@ -239,7 +238,7 @@ class Markers(object):
result[key] = MarkerLocation(attrs)
# Done
logger.debug("Loaded {0} markers from '{1}'.".format(len(result), file))
logger.info("Loaded {0} markers from '{1}'.".format(len(result), file))
return result
# Update given markers on the map
@ -254,11 +253,11 @@ class Markers(object):
# Scrape websites for data
file = self._getCachedMarkersFile()
cache = {}
logger.debug("Scraping KiwiSDR website...")
logger.info("Scraping KiwiSDR website...")
cache.update(self.scrapeKiwiSDR())
logger.debug("Scraping WebSDR website...")
logger.info("Scraping WebSDR website...")
cache.update(self.scrapeWebSDR())
logger.debug("Scraping OpenWebRX website...")
logger.info("Scraping OpenWebRX website...")
cache.update(self.scrapeOWRX())
# Save parsed data into a file, if there is anything to save
@ -339,7 +338,7 @@ class Markers(object):
result[rl.getId()] = rl
# Done
logger.debug("Loaded {0} transmitters from EIBI.".format(len(result)))
logger.info("Loaded {0} transmitters from EIBI.".format(len(result)))
return result
def scrapeOWRX(self, url: str = "https://www.receiverbook.de/map"):
@ -379,7 +378,7 @@ class Markers(object):
lon = lon + 0.0005
except Exception as e:
logger.debug("scrapeOWRX() exception: {0}".format(e))
logger.error("scrapeOWRX() exception: {0}".format(e))
# Done
return result
@ -409,7 +408,7 @@ class Markers(object):
result[rl.getId()] = rl
except Exception as e:
logger.debug("scrapeWebSDR() exception: {0}".format(e))
logger.error("scrapeWebSDR() exception: {0}".format(e))
# Done
return result
@ -463,7 +462,7 @@ class Markers(object):
entry[m.group(1).lower()] = m.group(2)
except Exception as e:
logger.debug("scrapeKiwiSDR() exception: {0}".format(e))
logger.error("scrapeKiwiSDR() exception: {0}".format(e))
# Done
return result

View File

@ -12,7 +12,6 @@ import time
import math
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
#
# Maximal distance a repeater can reach (kilometers)
@ -89,7 +88,7 @@ class Repeaters(object):
self.location = location
elif dist > 10:
# Do not delete repeater list unless receiver moved a lot
logger.debug("Receiver moved by {0}km, deleting '{1}'...".format(dist, file))
logger.info("Receiver moved by {0}km, deleting '{1}'...".format(dist, file))
self.location = location
os.remove(file)
@ -122,19 +121,19 @@ class Repeaters(object):
# Save database to a given JSON file.
#
def saveRepeaters(self, file: str, repeaters):
logger.debug("Saving {0} repeaters to '{1}'...".format(len(repeaters), file))
logger.info("Saving {0} repeaters to '{1}'...".format(len(repeaters), file))
try:
with open(file, "w") as f:
json.dump(repeaters, f, indent=2)
f.close()
except Exception as e:
logger.debug("saveRepeaters() exception: {0}".format(e))
logger.error("saveRepeaters() exception: {0}".format(e))
#
# Load database from a given JSON file.
#
def loadRepeaters(self, file: str):
logger.debug("Loading repeaters from '{0}'...".format(file))
logger.info("Loading repeaters from '{0}'...".format(file))
if not os.path.isfile(file):
result = []
else:
@ -143,10 +142,10 @@ class Repeaters(object):
result = json.load(f)
f.close()
except Exception as e:
logger.debug("loadRepeaters() exception: {0}".format(e))
logger.error("loadRepeaters() exception: {0}".format(e))
result = []
# Done
logger.debug("Loaded {0} repeaters from '{1}'...".format(len(result), file))
logger.info("Loaded {0} repeaters from '{1}'...".format(len(result), file))
return result
#
@ -169,7 +168,7 @@ class Repeaters(object):
url1 = url.format(script = s, lat = lat, lon = lon, range = rangeKm)
req = urllib.request.Request(url1, headers = hdrs)
data = urllib.request.urlopen(req).read().decode("utf-8")
logger.debug("Trying {0} ... got {1} bytes".format(url1, len(data)))
logger.info("Trying {0} ... got {1} bytes".format(url1, len(data)))
data = json.loads(data)
# ...until we get the result
if "results" in data and len(data["results"]) > 0:
@ -191,7 +190,7 @@ class Repeaters(object):
}]
except Exception as e:
logger.debug("loadFromWeb() exception: {0}".format(e))
logger.error("loadFromWeb() exception: {0}".format(e))
# Done
return result
@ -213,7 +212,7 @@ class Repeaters(object):
rxPos = (pm["receiver_gps"]["lat"], pm["receiver_gps"]["lon"])
# No result yet
logger.debug("Creating bookmarks for {0}-{1}kHz within {2}km...".format(f1//1000, f2//1000, rangeKm))
logger.info("Creating bookmarks for {0}-{1}kHz within {2}km...".format(f1//1000, f2//1000, rangeKm))
result = {}
# Search for repeaters within frequency and distance ranges
@ -227,10 +226,10 @@ class Repeaters(object):
result[f] = (entry, d)
except Exception as e:
logger.debug("getBookmarks() exception: {0}".format(e))
logger.error("getBookmarks() exception: {0}".format(e))
# Return bookmarks for all found entries
logger.debug("Created {0} bookmarks for {1}-{2}kHz within {3}km.".format(len(result), f1//1000, f2//1000, rangeKm))
logger.info("Created {0} bookmarks for {1}-{2}kHz within {3}km.".format(len(result), f1//1000, f2//1000, rangeKm))
return [ Bookmark({
"name" : result[f][0]["name"],
"modulation" : result[f][0]["mode"],
@ -247,7 +246,7 @@ class Repeaters(object):
rxPos = (pm["receiver_gps"]["lat"], pm["receiver_gps"]["lon"])
# No result yet
logger.debug("Looking for repeaters within {0}km...".format(rangeKm))
logger.info("Looking for repeaters within {0}km...".format(rangeKm))
result = []
# Search for repeaters within given distance range
@ -258,9 +257,9 @@ class Repeaters(object):
result += [entry]
except Exception as e:
logger.debug("getAllInRange() exception: {0}".format(e))
logger.error("getAllInRange() exception: {0}".format(e))
# Done
logger.debug("Found {0} repeaters within {1}km.".format(len(result), rangeKm))
logger.info("Found {0} repeaters within {1}km.".format(len(result), rangeKm))
return result

View File

@ -33,26 +33,26 @@ class TextParser(LineBasedModule):
def closeFile(self):
if self.file is not None:
try:
logger.debug("Closing log file '%s'." % self.file.name)
logger.info("Closing log file '%s'." % self.file.name)
self.file.close()
self.file = None
# Delete excessive files from storage
logger.debug("Performing storage cleanup...")
logger.info("Performing storage cleanup...")
Storage.getSharedInstance().cleanStoredFiles()
except Exception as exptn:
logger.debug("Exception closing file: %s" % str(exptn))
logger.error("Exception closing file: %s" % str(exptn))
self.file = None
def newFile(self, fileName):
self.closeFile()
try:
logger.debug("Opening log file '%s'..." % fileName)
logger.info("Opening log file '%s'..." % fileName)
self.file = Storage.getSharedInstance().newFile(fileName, buffering = 0)
self.cntLines = 0
except Exception as exptn:
logger.debug("Exception opening file: %s" % str(exptn))
logger.error("Exception opening file: %s" % str(exptn))
self.file = None
def writeFile(self, data):
@ -65,7 +65,7 @@ class TextParser(LineBasedModule):
try:
self.file.write(data)
except Exception as exptn:
logger.debug("Exception writing file: %s" % str(exptn))
logger.error("Exception writing file: %s" % str(exptn))
# No more than maxLines per file
self.cntLines = self.cntLines + 1
if self.cntLines >= self.maxLines:
@ -97,9 +97,9 @@ class TextParser(LineBasedModule):
return None
def run(self):
logger.debug("%s starting..." % self.myName())
logger.info("%s starting..." % self.myName())
super().run()
logger.debug("%s exiting..." % self.myName())
logger.info("%s exiting..." % self.myName())
def process(self, line: bytes) -> any:
# No result yet
@ -121,7 +121,7 @@ class TextParser(LineBasedModule):
self.writeFile(b"\n")
except Exception as exptn:
logger.debug("%s: Exception parsing: %s" % (self.myName(), str(exptn)))
logger.error("%s: Exception parsing: %s" % (self.myName(), str(exptn)))
# Return parsed result, ignore result in service mode
return out if out and not self.service else None