Celery:将任务日志转储到日志文件中

时间:2014-09-18 16:22:14

标签: python logging celery

只询问如何将任务日志转储到日志文件中。我尝试了以下但是没有用:

=== first / celeryconfig.py ===

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'standard': {
        'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
        'datefmt' : "%d/%b/%Y %H:%M:%S"
        },
    },
    'handlers': {
        'first.tasks.add': {
            'level' : 'INFO',
            'filters:' None,
            'class': 'logging.FileHandler',
            'filename': '/home/ubuntu/temp/add.log'
        }
    },
    'loggers': {
        'first.tasks.add': {
            'handlers' : ['first.tasks.add'],
            'level' : 'INFO',
            'propagate' : True,
        },
    }
}

=== first / tasks.py ===

from __future__ import absolute_import
from celery.utils.log import get_task_logger
from first.celery import app

@app.task
def add(x, y):
    logger = get_task_logger(__name__)
    logger.info('Adding {0} + {1}'.format(x, y))
    return x + y

非常感谢任何想法。提前谢谢!

0 个答案:

没有答案