DeepBlue/util/logging.py

27 lines
652 B
Python
Raw Normal View History

2020-01-08 01:26:36 +00:00
'''
Provides some simple logging utility
'''
2020-01-07 01:41:08 +00:00
import datetime
path = "logs/log.txt"
cleanup = open(path, "w+")
cleanup.close()
2020-01-08 01:26:36 +00:00
# Format: [DD.MM.YYYY HH:MM:SS] [<TYPE>] MESSAGE
def log(msg: str, log_type: str, mute: bool):
2020-01-07 01:41:08 +00:00
log = f"[{datetime.datetime.now().strftime('%d.%m.%Y %H:%M:%S')}] [{log_type.upper()}] {msg}"
log_file = open(path, "a")
log_file.write(log + "\n")
log_file.close()
if mute == False:
print(log)
2020-01-08 01:26:36 +00:00
def info(msg: str, mute: bool=False):
2020-01-07 01:41:08 +00:00
log(msg, "info", mute)
2020-01-08 01:26:36 +00:00
def warning(msg: str, mute: bool=False):
2020-01-07 01:41:08 +00:00
log(msg, "warning", mute)
2020-01-08 01:26:36 +00:00
def error(msg: str, mute: bool=False):
2020-01-07 01:41:08 +00:00
log(msg, "error", mute)