使用celery内置的日志模块记录日志

celery 日志配置

项目结构

celery_config.py

import logging.config
 
LOG_CONFIG = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'simple': {
            # 'datefmt': '%m-%d-%Y %H:%M:%S'
            'format': '%(asctime)s \"%(pathname)s:%(module)s:%(funcName)s:%(lineno)d\" [%(levelname)s]- %(message)s'
        }
    },
    'handlers': {
        'celery': {
            # 'level': 'INFO',
            # 'class': 'logging.handlers.RotatingFileHandler',
            'level': 'DEBUG',
            'formatter': 'simple',
            'class': 'logging.handlers.TimedRotatingFileHandler',
            'filename': 'your_name.log',
            'when': 'midnight',
            'encoding': 'utf-8',
        },
    },
    'loggers': {
         'myapp': {
            'handlers': ['celery'],
            'level': 'INFO',
            'propagate': True,
         }
    }
}
 
logging.config.dictConfig(LOG_CONFIG)

 

项目中的应用

 

猜你喜欢

转载自www.cnblogs.com/qybk/p/12668722.html