how to send multiple log files to amazon cloudwatch? how to send multiple log files to amazon cloudwatch? docker docker

how to send multiple log files to amazon cloudwatch?


In case of a container, I will never suggest writing logs to file, better to write logs container stdout and stderr.

Another interesting thing, how you will deal with logfile if you moved to fargate? so do not write logs to file and do not treat the container like instance machine.

The beauty of AWS log driver is, it pushes to logs to Cloud watch logs and from cloud watch it also super easy to push these to ELK.

Go for AWS log driver, design your entrypoint in way that it writes logs to stdout and stderr in the container. normally this is super easy when you run the process in the foreground it automatically writes log to container stdout.

Just add this line in your task definition and add cloud watch role.

            "logConfiguration": {                "logDriver": "awslogs",                "options": {                    "awslogs-group": "awslogs-wordpress",                    "awslogs-region": "us-west-2",                    "awslogs-stream-prefix": "awslogs-example"                }            }

or enter image description here

once it configured you will see the logs

enter image description here

Using the awslogs Log Driver

You can configure the containers in your tasks to send log information to CloudWatch Logs. If you are using the Fargate launch type for your tasks, this allows you to view the logs from your containers. If you are using the EC2 launch type, this enables you to view different logs from your containers in one convenient location, and it prevents your container logs from taking up disk space on your container instances. This topic helps you get started using the awslogs log driver in your task definitions.

Note

The type of information that is logged by the containers in your task depends mostly on their ENTRYPOINT command. By default, the logs that are captured show the command output that you would normally see in an interactive terminal if you ran the container locally, which are the STDOUT and STDERR I/O streams. The awslogs log driver simply passes these logs from Docker to CloudWatch Logs. For more information on how Docker logs are processed, including alternative ways to capture different file data or streams, see View logs for a container or service in the Docker documentation.

enter image description hereaws-ecs-log-driver