万年素人からHackerへの道

万年素人がHackerになれるまで殴り書きするぜ。

  • ・寄付お願いします
    YENTEN:YYzNPzdsZWqr5THWAdMrKDj7GT8ietDc2W
    BitZenny:ZfpUbVya8MWQkjjGJMjA7P9pPkqaLnwPWH
    c0ban:8KG95GXdEquNpPW8xJAJf7nn5kbimQ5wj1

なぜかAttributeError: 'module' object has no attribute 'handlers' Python

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)