-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot_log.py
38 lines (28 loc) · 1023 Bytes
/
bot_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
30
31
32
33
34
35
36
37
38
import logging
import os
class Logger:
def __init__(self, log_path):
# Enable logging
logger = logging.getLogger('fk-viikkotiedotebot')
logger.setLevel(logging.DEBUG)
# Create file handler for logs
try:
len(log_path)
except (NameError, TypeError):
log_path = os.path.join('logs', 'fk-viikkotiedotebot.log')
fh = logging.FileHandler(log_path)
fh.setLevel(logging.INFO)
# Create stream handler to output errors to console
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter)
logger.addHandler(fh)
logger.addHandler(ch)
self.logger = logger
if __name__ == '__main__':
test_logger = Logger(None).logger
test_logger.debug('testdebug')
test_logger.info('testinfo')
test_logger.error('testerror')