Skip to content

[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


debug log

insert this snippet before bot.run()

import logging

logging.basicConfig(level='DEBUG')

log to file

  1. move all log to file, not preserve console log
logging.basicConfig(filename='/path/to/your/log', encoding='utf-8')
  1. 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

log format

logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

remind: logging.basicConfig is available for only the first call