Skip to content

ECS logs of one day is distributed over multi folders

0

I noticed that, the logs of one day of the ECS task is distributed over multi folders. For example: 2024/11/12/[$LATEST]56238748a485430db2e587ee4e38fce2 2024/11/12/[$LATEST]dba2c42367514e2498f8c479ec7d9473 2024/11/12/[$LATEST]10dd6d84a16e4847813ab8d04a53d7d1

How can I set the logs of each day in one folder at CW?

The task definition of this part is: "logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-group": "/ecs/node", "awslogs-create-group": "true", "awslogs-region": "us-east-1", "awslogs-stream-prefix": "ecs" }

I tried to use {date} like the approach that worked with me with EC2-CW config file, but it didn't work.

2 Answers
0

The behavior you're observing is expected and is related to how Amazon ECS manages log streams for tasks. Each unique task instance creates its own log stream within the specified log group. The [$LATEST] followed by a unique identifier in the log stream name represents individual task runs.

Unfortunately, there isn't a direct way to consolidate all logs from a single day into one folder in CloudWatch Logs using just the ECS task definition configuration. The log stream creation is managed by ECS and is designed to separate logs for each task run for easier troubleshooting and management.

However, you can improve the organization of your logs by modifying the awslogs-stream-prefix in your task definition. Instead of just "ecs", you could use a more descriptive prefix that includes the date. For example:

"logConfiguration": {
    "logDriver": "awslogs",
    "options": {
        "awslogs-group": "/ecs/node",
        "awslogs-create-group": "true",
        "awslogs-region": "us-east-1",
        "awslogs-stream-prefix": "ecs-{date}"
    }
}

While this won't consolidate all logs into a single folder, it will group them more logically by date, making it easier to find logs for a specific day.

If you need to analyze logs across multiple streams, you can use CloudWatch Logs Insights, which allows you to query across multiple log streams within a log group. This can help you view and analyze logs from multiple task runs together, even if they're in separate streams.

For more advanced log aggregation and analysis, you might consider using additional tools or services that can collect logs from multiple streams and consolidate them based on your specific requirements.
Sources
ECS task definition logging configuration | AWS re:Post
LogConfiguration - Amazon Elastic Container Service

answered 2 years ago

EXPERT

reviewed 2 years ago

0

These are not folders but as the agent says a log stream for each task.

A new one gets created if your ecs tasks dies or is restarted. Your container may be crashing several times so it restarts. Check the contents logs for why it crashed and the ECS cluster logs.

EXPERT

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.