我正在使用Fargate。我的容器正在运行两个进程。芹菜工作者在背景中和在前景的Django。前台进程将日志发送到stdout,因此AWS负责将Django日志发送到相关的Cloudwatch Log Group和Stream。
由于它在后台运行,如何将芹菜工作者的日志发送到(同一日志组中的不同日志流)Cloudwatch?
如果无法将第二个进程移动到单独的容器并像往常一样进行记录,则可以将awslogs包安装到容器中并将其设置为读取后台进程的日志文件并将内容发送到CloudWatch。但我不推荐这种方法。
同样,这不一定是基于Fargate
的问题或问题。登录芹菜请查看http://docs.celeryproject.org/en/latest/userguide/tasks.html#logging。
The worker won’t update the redirection if you create a logger instance somewhere in your task or task module. If you want to redirect sys.stdout and sys.stderr to a custom logger you have to enable this manually, for example: import sys logger = get_task_logger(__name__) @app.task(bind=True) def add(self, x, y): old_outs = sys.stdout, sys.stderr rlevel = self.app.conf.worker_redirect_stdouts_level try: self.app.log.redirect_stdouts_to_logger(logger, rlevel) print('Adding {0} + {1}'.format(x, y)) return x + y finally: sys.stdout, sys.stderr = old_outs
对于使用Fargate进行日志记录,我会使用awslogs
驱动程序。以下是您在此处记录的配置方式:https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_awslogs.html
如果使用控制台:
或者如果在cloudformation模板中: