You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.7 KiB
54 lines
1.7 KiB
#-*-coding utf-8-*- |
|
# Общественное достояние 2023, Алексей Безбородов (Alexei Bezborodov) <AlexeiBv+mirocod_platform_bot@narod.ru> |
|
|
|
# --------------------------------------------------------- |
|
# Логирование событий в файл |
|
|
|
# Четыре типа уведомлений: |
|
# Info - Информация. |
|
# Warn - Предупреждение. |
|
# Error - Ошибка. |
|
# Success - Успех. |
|
|
|
# Файл лога |
|
g_log_file_name = 'log.txt' |
|
|
|
from botsys import config |
|
import colorama |
|
import datetime |
|
colorama.init() |
|
|
|
def GetTime(): |
|
now = datetime.datetime.now() |
|
time = now.strftime(f"[%d.%m.%Y, %H:%M]") |
|
return time |
|
|
|
def Info(a_LogMessage): |
|
time = GetTime() |
|
WriteToFile(f'{time} | {a_LogMessage}') |
|
print(f"{time} {colorama.Back.BLUE}{colorama.Style.BRIGHT} ИНФО {colorama.Style.RESET_ALL} | {a_LogMessage}") |
|
|
|
def Warn(a_LogMessage): |
|
time = GetTime() |
|
WriteToFile(f'{time} | {a_LogMessage}') |
|
print(f"{time} {colorama.Back.YELLOW}{colorama.Style.BRIGHT} ВНИМАНИЕ {colorama.Style.RESET_ALL} | {a_LogMessage}") |
|
|
|
def Error(a_LogMessage): |
|
time = GetTime() |
|
WriteToFile(f'{time} | {a_LogMessage}') |
|
print(f"{time} {colorama.Back.RED}{colorama.Style.BRIGHT} ОШИБКА {colorama.Style.RESET_ALL} | {a_LogMessage}") |
|
|
|
def Success(a_LogMessage): |
|
time = GetTime() |
|
WriteToFile(f'{time} | {a_LogMessage}') |
|
print(f"{time} {colorama.Back.GREEN}{colorama.Style.BRIGHT} УСПЕХ {colorama.Style.RESET_ALL} | {a_LogMessage}") |
|
|
|
def WriteToFile(a_LogMessage): |
|
if config.g_log_to_file != True: |
|
return |
|
|
|
f = open(g_log_file_name, 'a+') |
|
f.write(a_LogMessage) |
|
f.write('\n') |
|
f.close() |
|
|
|
|