-
Notifications
You must be signed in to change notification settings - Fork 1
/
errorlogging.py
70 lines (57 loc) · 2.62 KB
/
errorlogging.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import logging
from filepath import Filepath
def getLogger(activeDate, sN, vMN):
## Create logger that handles file logging
logger = logging.getLogger()
# handler to write to logs
fileHandler = logging.FileHandler(Filepath.get_log_file(activeDate, sN, vMN))
formatter = logging.Formatter('%(asctime)s %(message)s\n')
fileHandler.setFormatter(formatter)
# add handlers to logger
logger.addHandler(fileHandler)
# Set logger level
logger.setLevel(20) # info level
return logger
def logError(username, password, p1, p2, exception, logger):
"""
string string TupleOfStrings TupleOfStrings Exception logger -> None
username: str | username of account being updated at the time of exception
password: str | password of account being updated at the time of exception
p1: TupleOfStrings | (firstName, lastName, team) of first player
being added to account at time of exception
p2: TupleOfStrings | (firstName, lastName, team) of second player
being added to account at time of exception (possible empty)
exception: Exception | the exception raised
logger: logger | logger to use to log errors
Logs the error to file
"""
# we don't check the type of exception because i don't know how to do that
assert type(username) == str
assert type(password) == str
assert (type(p1) == tuple) or not p1
assert (type(p2) == tuple) or not p2
assert type(logger) == logging.RootLogger
logger.error("Unit account update failure: {}, {}".format(username, password))
logger.error(" p1, p2: {}, {}".format(p1, p2))
logger.error(exception, exc_info=True)
def logFailedAccounts(**kwargs):
"""
kwargs -> None
df: dataframe containing all the accounts
updatedUsernames: tuple of succesffuly updated usernames
logger: logger object
Logs the failedAccounts to today's error log in the event that
the main while loop in chooseplayers.py failed to update all playres
"""
import pandas as pd
logger = kwargs['logger']
## Get a list of the failed accounts
failedAccounts = []
for dummyIndex, index, username, password, sN, vMN in kwargs['df'].itertuples():
if username not in kwargs['updatedUsernames']:
failedAccounts.append((str(username), str(password)))
# log those errors baby
logger.error("{} of {} accounts failed".format(
len(failedAccounts), len(kwargs['df']) ))
for failedAccount in failedAccounts:
logger.error(" U, P: {}, {}".format(failedAccount[0], failedAccount[1]))