What argument do I pass to the get_task_logger() function of celery?
celery, python
Solution
As of 2014-10-05, this is no longer the case. Passing `__name__` now seems to work fine (current implementation).
Just remember that your task loggers will still be forced to inherit from `celery.task`. Its parent logger `celery` does not propagate to the root logger by default, so you might want to define a logger for `celery.task` in your logging configuration.
Problem
The celery 3.x docs on logging recommend to set up the task logger like so: ``` from celery.utils.log import get_task_logger logger = get_task_logger(__name__) ``` When I do that, `CELERYD_TASK_LOG_FORMAT` is ignored and the log statements use `CELERYD_LOG_FORMAT` instead, where I cannot make use of `%(task_name)s` and `%(task_id)s`. My task is in a module `tasks` in my app `myapp`. Therefore, `__name__` is `myapp.tasks`. I assume the problem are these lines in `celery/utils/log.py`: ``` def get_task_logger(name): logger = get_logger(name) if logger.parent is logging.root: logger.parent = task_logger return logger ``` So for whatever reason, the module passed to `get_task_logger()` has to be a first level module, otherwise the task logger is not attached. There is no comment explaining why this has to be the case (and I can't think of any reason why you would add this restriction, really). `__name__` doesn't work because it references a second level module. Am I making a mistake or are the docs just wrong? If so, what am I supposed to pass to `get_task_logger()` instead?