вторник, 13 декабря 2011 г.

Celery loader hijacks/replaces standard logging configuration

Оказывается celeryd загрузчик перекрывает стандартную logging конфигурацию для того чтобы облегчить жизнь разработчику.

Иинциатива конечно хорошая, однако для нас это было полной неожиданностью.

К счастью есть как минимум два способа изменить это поведение.

Быстрое, но не совсем полное решение это установить CELERYD_HIJACK_ROOT_LOGGER = False.

Чуть более сложное, но концептуально верное решение это использовать setup-logging хук/сигнал, который предоставляет Celery.

Ссылки:

In 2.1 logging behavior was changed to not configure logging if it was already configured. The problem is that some libraries does not play nice and hijack the root logger, or use logging.basicConfig – resulting in users not getting any output or logs.
http://readthedocs.org/docs/celery/en/release21-maint/changelog.html#version-2-1-4

By default any previously configured logging options will be reset, because the Celery programs “hijacks” the root logger.
If you want to customize your own logging then you can disable this behavior.
http://ask.github.com/celery/configuration.html#celeryd-hijack-root-logger

setup_logging signal.
Celery won’t configure the loggers if this signal is connected, so you can use this to completely override the logging configuration with your own.
http://ask.github.com/celery/userguide/signals.html#setup-logging