-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.py
43 lines (31 loc) · 1.13 KB
/
logger.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
39
40
41
42
43
from helpers import get_meta_from_update
from logging import getLogger, StreamHandler, FileHandler, DEBUG
from sys import stdout
def log_cateify(func):
"""
A decorator that logs important cateification info (i.e.
when we're calling into the response controller).
"""
def _log_wrapper(bot, update):
username, user_id, query = get_meta_from_update(update)
log.debug('Processing: "{text}" from user {username} ({id})'.format(
text=query, username=username, id=user_id
))
return func(bot, update)
return _log_wrapper
def log_command(func):
"""
A decorator that logs important COMMANDification info (i.e.
when /commands are used).
"""
def _log_wrapper(bot, update):
username, user_id, command = get_meta_from_update(update)
log.debug('Command: "{command}" from user {username} ({id})'.format(
command=command, username=username, id=user_id
))
return func(bot, update)
return _log_wrapper
log = getLogger(__name__)
log.setLevel(DEBUG)
log.addHandler(StreamHandler(stdout))
log.addHandler(FileHandler('cateify_bot.log'))