forked from akmayer/Warframe-Algo-Trader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomLogger.py
31 lines (24 loc) · 819 Bytes
/
customLogger.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
import os
from datetime import datetime
logDir = "logs"
def makeGitIgnore():
with open(os.path.join(logDir, ".gitignore"), "w") as gitignore:
gitignore.write("# Ignore everything in this directory\n*\n# Except this file\n!.gitignore")
def verifyLogDir():
if os.path.exists(os.path.join(logDir, ".gitignore")):
return
if os.path.exists(logDir):
makeGitIgnore()
return
os.mkdir(logDir)
makeGitIgnore()
def writeTo(logFileName, line):
verifyLogDir()
with open(os.path.join(logDir, logFileName), "a") as logFile:
logFile.write(f"{datetime.today()}\t{line}\n")
def clearFile(logFileName):
verifyLogDir()
with open(os.path.join(logDir, logFileName), "w") as logFile:
logFile.write("")
if __name__ == "__main__":
verifyLogDir()