import logging def __create_file_log_handler(app): info_log = os.path.join(app.config['LOG_FOLDER'], 'info.log') info_file_handler = logging.handlers.RotatingFileHandler(info_log, maxBytes=100000, backupCount=10) info_file_handler.setLevel(logging.INFO) info_file_handler.setFormatter(logging.Formatter( '%(asctime)s %(levelname)s: %(message)s ' '[in %(pathname)s:%(lineno)d]') ) app.logger.addHandler(info_file_handler)
logging.handlersでなぜか
AttributeError: 'module' object has no attribute 'handlers' Python
と、怒られる。
loggingにはhandlersあるのに。
import logging import logging.handlers #これ追加 def __create_file_log_handler(app): info_log = os.path.join(app.config['LOG_FOLDER'], 'info.log') info_file_handler = logging.handlers.RotatingFileHandler(info_log, maxBytes=100000, backupCount=10) info_file_handler.setLevel(logging.INFO) info_file_handler.setFormatter(logging.Formatter( '%(asctime)s %(levelname)s: %(message)s ' '[in %(pathname)s:%(lineno)d]') ) app.logger.addHandler(info_file_handler)