I'm trying to customize date formatting of my celery app's log results when to write into a file. I couldn't find a way to handle this issue.
from celery import Celery
from celery import signals
app = Celery("myApp")
@signals.celeryd_init.connect
def setup_log_format(sender, conf, **kwargs):
conf.worker_log_format = """
[%(asctime)s] %(levelno)s [%(levelname)s] %(name)s: %(message)s
""".strip().format(sender)
conf.worker_task_log_format = (
"[%(asctime)s] %(levelno)s [%(levelname)s] %(name)s: %(message)s"
).format(sender)
TaskA.py
from celery.utils.log import get_task_logger
logger = get_task_logger(__name__)
if x:
logger.info(f"this is {x}")
What I see in the log file is:
[2020-07-13 14:59:30,182] 10 [INFO] This is True
What I want to have is:
[2020-07-13T14:59:30.182606Z] 10 [INFO] This is True
Obviously this feature is not implemented yet on celery side. Can you please tell me if you see any way to solve this issue ?
Thanks in advance for your help.
Ps. I use celery with Django fwk.