-
Notifications
You must be signed in to change notification settings - Fork 43
[FAQ] logs
Housa Hitomi edited this page Apr 26, 2022
·
2 revisions
FYI: khl.py uses standard logging library to log, thus you can modify its behavior easily via standard way
recommend: the official HOWTO: https://docs.python.org/3/howto/logging.html
insert this snippet before bot.run()
import logging
logging.basicConfig(level='DEBUG')
- move all log to file, not preserve console log
logging.basicConfig(filename='/path/to/your/log', encoding='utf-8')
- stream to file and console
h = logging.FileHandler('/path/to/your/log', encoding='utf-8')
h.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
logging.getLogger('khl').addHandler(h)
setFormatter()
since h
's default formatter is unfriendly for debugging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
remind: logging.basicConfig
is available for only the first call