Add additional logging to services

This commit is contained in:
Ebag333
2017-02-28 10:32:03 -08:00
parent c97a388fc4
commit ff5d40dcd3
8 changed files with 39 additions and 6 deletions

View File

@@ -194,11 +194,13 @@ class Character(object):
@staticmethod
def backupSkills(path, saveFmt, activeFit, callback):
thread = SkillBackupThread(path, saveFmt, activeFit, callback)
pyfalog.debug("Starting backup skills thread.")
thread.start()
@staticmethod
def importCharacter(path, callback):
thread = CharacterImportThread(path, callback)
pyfalog.debug("Starting import character thread.")
thread.start()
@staticmethod

View File

@@ -246,6 +246,7 @@ class Fit(object):
try:
implant = es_Implant(item)
except ValueError:
pyfalog.warning("Invalid item: {0}", itemID)
return False
fit.implants.append(implant)
@@ -272,6 +273,7 @@ class Fit(object):
try:
booster = es_Booster(item)
except ValueError:
pyfalog.warning("Invalid item: {0}", itemID)
return False
fit.boosters.append(booster)
@@ -432,6 +434,7 @@ class Fit(object):
try:
m = es_Module(item)
except ValueError:
pyfalog.warning("Invalid item: {0}", itemID)
return False
if m.item.category.name == "Subsystem":
@@ -479,6 +482,7 @@ class Fit(object):
try:
m = es_Module(item)
except ValueError:
pyfalog.warning("Invalid item: {0}", newItemID)
return False
if m.fits(fit):
@@ -519,6 +523,7 @@ class Fit(object):
if cargoP.isValidState(State.ACTIVE):
cargoP.state = State.ACTIVE
except:
pyfalog.warning("Invalid item: {0}", cargo.item)
return
if cargoP.slot != module.slot: # can't swap modules to different racks

View File

@@ -21,10 +21,13 @@
import urllib2
import urllib
import socket
from logbook import Logger
import config
from service.settings import NetworkSettings
pyfalog = Logger(__name__)
# network timeout, otherwise pyfa hangs for a long while if no internet connection
timeout = 3
socket.setdefaulttimeout(timeout)
@@ -76,6 +79,7 @@ class Network(object):
access = NetworkSettings.getInstance().getAccess()
if not self.ENABLED & access or not type & access:
pyfalog.warning("Access not enabled - please enable in Preferences > Network")
raise Error("Access not enabled - please enable in Preferences > Network")
# Set up some things for the request
@@ -113,6 +117,8 @@ class Network(object):
try:
return urllib2.urlopen(request)
except urllib2.HTTPError as error:
pyfalog.warning("HTTPError:")
pyfalog.warning(error)
if error.code == 404:
raise RequestError()
elif error.code == 403:
@@ -120,6 +126,8 @@ class Network(object):
elif error.code >= 500:
raise ServerError()
except urllib2.URLError as error:
pyfalog.warning("Timed out or other URL error:")
pyfalog.warning(error)
if "timed out" in error.reason:
raise TimeoutError()
else:

View File

@@ -83,11 +83,13 @@ class Port(object):
@staticmethod
def backupFits(path, callback):
pyfalog.debug("Starting backup fits thread.")
thread = FitBackupThread(path, callback)
thread.start()
@staticmethod
def importFitsThreaded(paths, callback):
pyfalog.debug("Starting import fits thread.")
thread = FitImportThread(paths, callback)
thread.start()
@@ -105,12 +107,14 @@ class Port(object):
fits = []
for path in paths:
if callback: # Pulse
pyfalog.debug("Processing file:\n{0}", path)
wx.CallAfter(callback, 1, "Processing file:\n%s" % path)
file_ = open(path, "r")
srcString = file_.read()
if len(srcString) == 0: # ignore blank files
pyfalog.debug("File is blank.")
continue
codec_found = None
@@ -165,6 +169,7 @@ class Port(object):
_, fitsImport = Port.importAuto(srcString, path, callback=callback, encoding=codec_found)
fits += fitsImport
except xml.parsers.expat.ExpatError:
pyfalog.warning("Malformed XML in:\n{0}", path)
return False, "Malformed XML in %s" % path
except Exception as e:
pyfalog.critical("Unknown exception processing: {0}", path)
@@ -181,6 +186,7 @@ class Port(object):
db.save(fit)
IDs.append(fit.ID)
if callback: # Pulse
pyfalog.debug("Processing complete, saving fits to database: {0}/{1}", i + 1, numFits)
wx.CallAfter(
callback, 1,
"Processing complete, saving fits to database\n(%d/%d)" %
@@ -612,7 +618,7 @@ class Port(object):
if m.fits(fit):
m.owner = fit
if not m.isValidState(m.state):
print("Error: Module", m, "cannot have state", m.state)
pyfalog.warning("Error: Module {0} cannot have state {1}", m, m.state)
fit.modules.append(m)
@@ -810,8 +816,9 @@ class Port(object):
if callback:
wx.CallAfter(callback, None)
# Skip fit silently if we get an exception
except Exception:
except Exception as e:
pyfalog.error("Caught exception on fit.")
pyfalog.error(e)
pass
return fits
@@ -835,8 +842,9 @@ class Port(object):
f.ship = Ship(sMkt.getItem(shipType))
except ValueError:
f.ship = Citadel(sMkt.getItem(shipType))
except:
except Exception as e:
pyfalog.warning("Caught exception on importXml")
pyfalog.error(e)
continue
hardwares = fitting.getElementsByTagName("hardware")
moduleList = []
@@ -845,8 +853,9 @@ class Port(object):
moduleName = hardware.getAttribute("type")
try:
item = sMkt.getItem(moduleName, eager="group.category")
except:
except Exception as e:
pyfalog.warning("Caught exception on importXml")
pyfalog.error(e)
continue
if item:
if item.category.name == "Drone":

View File

@@ -59,6 +59,7 @@ if config.saveDB and os.path.isfile(config.saveDB):
else:
# If database does not exist, do not worry about migration. Simply
# create and set version
pyfalog.debug("Existing database not found, creating new database.")
db.saveddata_meta.create_all()
db.saveddata_engine.execute('PRAGMA user_version = {}'.format(migration.getAppVersion()))
# Import default database values

View File

@@ -104,6 +104,7 @@ class Price(object):
try:
percprice = float(sell.getElementsByTagName("percentile").item(0).firstChild.data)
except (TypeError, ValueError):
pyfalog.warning("Failed to get price for: {0}", type_)
percprice = 0
# Fill price data

View File

@@ -82,11 +82,15 @@ class AuthHandler(BaseHTTPServer.BaseHTTPRequestHandler):
try:
if step2:
self.server.callback(parts)
pyfalog.info("Successfully logged into CREST.")
msg = "If you see this message then it means you should be logged into CREST. You may close this window and return to the application."
else:
# For implicit mode, we have to serve up the page which will take the hash and redirect useing a querystring
pyfalog.info("Processing response from EVE Online.")
msg = "Processing response from EVE Online"
except Exception, ex:
pyfalog.error("Error in CREST AuthHandler")
pyfalog.error(ex)
msg = "<h2>Error</h2>\n<p>{}</p>".format(ex.message)
finally:
self.send_response(200)
@@ -127,6 +131,7 @@ class StoppableHTTPServer(BaseHTTPServer.HTTPServer):
pass
def stop(self):
pyfalog.warning("Setting CREST server to stop.")
self.run = False
def handle_timeout(self):

View File

@@ -85,8 +85,9 @@ class CheckUpdateThread(threading.Thread):
if release['prerelease'] and rVersion > config.expansionVersion:
wx.CallAfter(self.callback, release) # Singularity -> Singularity
break
except:
pyfalog.warning("Caught exception in run")
except Exception as e:
pyfalog.error("Caught exception in run")
pyfalog.error(e)
pass
@staticmethod
@@ -100,6 +101,7 @@ class Update(object):
@staticmethod
def CheckUpdate(callback):
thread = CheckUpdateThread(callback)
pyfalog.debug("Starting Check Update Thread.")
thread.start()
@classmethod