-
Notifications
You must be signed in to change notification settings - Fork 0
/
logs.py
34 lines (26 loc) · 1.18 KB
/
logs.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
# coding: utf8
import sys
import time
reload(sys)
sys.setdefaultencoding('utf8')
# Модуль логов
# ----------------------------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------------------------
def sys_time():
return time.time()
def log_write(log_file, scenario, action, user='', log_user_id=''):
log_time = sys_time()
tuple_time = time.gmtime(log_time)
# log_time = int(log_time)
res_time = time.strftime('%Y-%m-%d %H:%M:%S', tuple_time)
if scenario == 'usr':
log_file.write('{0}: @{1} ({2}) написал: "{3}"\n'.format(
res_time, user, log_user_id, action))
elif scenario == 'bot':
log_file.write('{0}: ---> @{1} ({2}) бот ответил: "{3}"\n'.format(
str(res_time), user, log_user_id, action))
elif scenario == 'sys':
log_file.write('{0}: {1}\n'.format(res_time, action))
elif scenario == 'endl':
log_file.write('\n')