How do I forward logs created by a process inside a ECS Fargate task to Cloudwatch

0

I have the following in my ECS Fargate task definition that is starting up a container.

"logConfiguration": {
    "logDriver": "awslogs",
    "options": {
        "awslogs-group": "my-log-group",
        "awslogs-region": "us-east-1",
        "awslogs-stream-prefix": "my-log-stream-prefix"
    }
}

I see the logs thrown by the entrypoint.sh script of the docker container. But I also want to send/view the logs from /home/my-app/application.log from inside the conatiner, which only get's created and populated after the container starts up.

已提问 1 年前1330 查看次数
2 回答
0
已接受的回答

If the log driver is awslogs, logs can be output to CloudWatch logs by setting the output destination to "/dev/stdout" or "/dev/stderr".
https://repost.aws/knowledge-center/ecs-container-logs-cloudwatch

The awslogs log driver simply passes the container logs that are the STDOUT and STDERR I/O streams from Docker to CloudWatch Logs. Therefore, verify that your application sends the logs to STDOUT and STDERR I/O streams. Be sure to set the correct log level for your application during the container build. Depending on your application, you might set the log level through an environment variable or a configuration file.

So, if you output "/home/my-app/application.log" to "/dev/stdout", you can check it in CloudWatch logs.

profile picture
专家
已回答 1 年前
0

Initially I assumed I would need to change all my logger statements in the processes that log. Found another solution online. Add the below line to send the logs to stdout in the Dockerfile.

RUN ln -sf /proc/1/fd/1 /home/my-app/application.log
已回答 1 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则