LoginSignup
0
0

More than 5 years have passed since last update.

よく使う Python ロギングスニペット

Last updated at Posted at 2018-10-09

完全に自分向け。
DEBUG 以上のログを Hourly でローテートしつつファイルに書き出し。

import logging
from logging import getLogger, Formatter
from logging.handlers import TimedRotatingFileHandler

logger = getLogger('ConvertLog')
logger.setLevel(logging.DEBUG)
rotate_handler = TimedRotatingFileHandler(filename='convert.log', when='H')
rotate_handler.setFormatter(Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
logger.addHandler(rotate_handler)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0