forked from Ghostofapacket/socialscrape-bot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
log.py
29 lines (25 loc) · 1.14 KB
/
log.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
import datetime
import threading
import file
import settings
class Log(threading.Thread):
def __init__(self, file_name):
threading.Thread.__init__(self)
self.file_name = file_name
self.file = file.File(self.file_name)
def log(self, strings, priority='INFO'):
time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
for string in [string.strip() for string in strings.strip().splitlines()]:
message = '[{time}] {version} - {priority} - {string}'.format(
time=time, priority=priority, version=settings.version,
string=string)
self.file.append('{message}\n'.format(message=message))
if priority == 'ERROR':
settings.irc_bot.send('PRIVMSG',
'I just crashed. See the log for more information.',
settings.irc_channel_main)
settings.irc_bot.send('PRIVMSG',
'I just crashed. See the log for more information.',
settings.irc_channel_bot)
raise Exception(string)
print(message.strip())