.BANCHO. Thread safe log to file

This commit is contained in:
Nyo
2016-06-06 12:39:24 +02:00
parent bd8c810f45
commit c8f9825e6b
5 changed files with 53 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ from helpers.systemHelper import runningUnderUnix
from objects import glob
ENDL = "\n" if runningUnderUnix() else "\r\n"
def logMessage(message, alertType = "INFO", messageColor = bcolors.ENDC, discord = False, alertDev = False, of = None, stdout = True):
"""
Logs a message to stdout/discord/file
@@ -52,9 +53,12 @@ def logMessage(message, alertType = "INFO", messageColor = bcolors.ENDC, discord
# Log to file if needed
if of != None:
# TODO: Lock
with open(".data/{}".format(of), "a") as f:
f.write(finalMessage+ENDL)
try:
glob.fLocks.lockFile(of)
with open(".data/{}".format(of), "a") as f:
f.write(finalMessage+ENDL)
finally:
glob.fLocks.unlockFile(of)
def warning(message, discord = False, alertDev = False):
"""