How to capture stdout of remote celery worker?

后端 未结 1 1497
执念已碎
执念已碎 2021-01-25 23:02

I have a setup with multiple remote Celery workers. In the main program which is starting tasks via apply_async I need continuous access to stdout of active remote workers.

相关标签:
1条回答
  • 2021-01-25 23:05

    I think you should set up your SysLogHandler. CELERY_REDIRECT_STDOUTS and CELERY_REDIRECT_STDOUTS_LEVEL are working by default with current logger.

    You can try example so (on remote servert):

    import logging
    from logging.handlers import SysLogHandler
    
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    # host is your server that used for the log
    syslog = SysLogHandler(address=(host, port))
    formatter = logging.Formatter('%(name)s: %(levelname)s %(message)s')
    syslog.setFormatter(formatter)
    logger.addHandler(syslog)
    
    # check it
    logger.info("Test test")
    
    0 讨论(0)
提交回复
热议问题