forked from swrlly/vrelay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.py
34 lines (24 loc) · 791 Bytes
/
Logger.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
import os
import re
import sys
class Logger:
path = "logs/"
def openLogFile(self):
# check next
allLogs = os.listdir(self.path)
log = None
# if no files, create new aoelog 0
if allLogs == []:
log = open(self.path + "aoelog 0.txt", "a")
# if some files
else:
# check for aoelog # number
try:
num = 0
for l in allLogs:
logNumber = int(re.search('\s([0-9]+)', l).group(0))
num = max(num, logNumber + 1)
log = open(self.path + "aoelog {}.txt".format(num), "a")
except:
log = open(self.path + "aoelog 0.txt", "a")
sys.stdout = log