diff --git a/content/en/agent/amazon_ecs/logs.md b/content/en/agent/amazon_ecs/logs.md index 0cb05afa193..046a8f73ce1 100644 --- a/content/en/agent/amazon_ecs/logs.md +++ b/content/en/agent/amazon_ecs/logs.md @@ -111,6 +111,8 @@ To collect all logs written by running applications in your ECS containers and s ### Custom log collection +#### Configuration file + If your container writes any logs to files, follow the [Custom Log Collection documentation][1] to tail files for logs. To gather logs from your `` application stored in `/.log` create a `.d/conf.yaml` file at the root of your [Agent's configuration directory][2] with the following content: @@ -125,6 +127,12 @@ logs: **Note**: Container metadata is not retrieved with custom log collection, therefore the Agent does not automatically assign container tags to logs. Use [custom tags][3] to create container tags. +#### Container label + +With Agent v7.25.0+/6.25.0+, it is possible to enable file tailing by using a container label so the logs collected receive the tags of the container on which the label was set. See this [example][4] that details the exact label to use. + +**Note**: The file paths are always relative to the Agent. So, this requires extra configuration for involved ECS tasks to share a directory between the container writing to the file and the Agent container. Refer to the [AWS documentation][5] for additional details on volume management with ECS. + ## Activate log integrations The `source` attribute is used to identify the integration to use for each container. Override it directly in your containers labels to start using [log integrations][1]. Read Datadog's [Autodiscovery guide for logs][2] to learn more about this process. @@ -136,3 +144,5 @@ The `source` attribute is used to identify the integration to use for each conta [1]: /agent/logs/?tab=tailfiles#custom-log-collection [2]: /agent/logs/#custom-log-collection [3]: /getting_started/tagging/assigning_tags/?tab=noncontainerizedenvironments#methods-for-assigning-tags +[4]: /agent/docker/log/?tab=logcollectionfromfile#examples +[5]: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/bind-mounts.html diff --git a/content/en/agent/docker/log.md b/content/en/agent/docker/log.md index 79a70ecf76b..30964575bb6 100644 --- a/content/en/agent/docker/log.md +++ b/content/en/agent/docker/log.md @@ -36,7 +36,7 @@ Configuring log collection depends on your current environment. Choose one of th - If you cannot deploy the containerized Agent and your container writes **all** logs to `stdout`/`stderr`, follow the [host Agent](?tab=hostagent#installation) installation to enable containerized logging within your Agent configuration file. -- If your container writes logs to files (only partially writes logs to `stdout`/`stderr` and writes logs to files OR fully writes logs to files), follow the [host Agent with custom log collection](?tab=hostagentwithcustomlogging#installation) installation. +- If your container writes logs to files (only partially writes logs to `stdout`/`stderr` and writes logs to files OR fully writes logs to files), follow the [host Agent with custom log collection](?tab=hostagentwithcustomlogging#installation) installation or follow the [containerized Agent](?tab=containerized-agent#installation) installation and check the [log collection from file with Autodiscovery configuration example](?tab=logcollectionfromfile#examples). ## Installation @@ -228,6 +228,31 @@ See the [multi-line processing rule documentation][1] to get more pattern exampl [1]: /agent/logs/advanced_log_collection/#multi-line-aggregation +{{% /tab %}} +{{% tab "From file" %}} + +The Agent v7.25.0+/6.25.0+ can directly collect logs from a file based on a container Autodiscovery label. To collect these logs, use the `com.datadoghq.ad.logs` label as shown below on your containers to collect `/logs/app.log`: + +```yaml +labels: + com.datadoghq.ad.logs: '[{"type":"file", "source": "sample_app", "service": "sample_service", "path": "/logs/app/prod.log"}]' +``` + +Logs collected from a file are tagged with the container metadata. Log collection is linked to the container life cycle, as soon as the container stops, log collection from that file stops. + + +**Notes**: + +- The file path is **relative** to the Agent, so the directory containing the file should be shared between the container running the application and the Agent container. For example, if the container mounts `/logs` each container logging to file may mount a volume such as `/logs/app` where the log file is written. + +- When using this kind of label on a container, its `stderr`/`stdout` logs are not collected automatically. If collection from both `stderr`/`stdout` and a file are needed it should be explicity enabled by using a label, for example: +```yaml +labels: + com.datadoghq.ad.logs: '[{"type":"file", "source": "java", "service": "app", "path": "/logs/app/prod.log"}, {"type": "docker", "source": "app_container", "service": "app"}]' +``` + +- When using this kind of combination, `source` and `service` have no default value and should be explicitly set in the Autodiscovery label. + {{% /tab %}} {{< /tabs >}}