GenericLogDriver

class aws_cdk.aws_ecs.GenericLogDriver(*, log_driver, options=None, secret_options=None)

Bases: LogDriver

A log driver that sends logs to the specified driver.

ExampleMetadata:

infused

Example:

# Create a Task Definition for the container to start
task_definition = ecs.Ec2TaskDefinition(self, "TaskDef")
task_definition.add_container("TheContainer",
    image=ecs.ContainerImage.from_registry("example-image"),
    memory_limit_mi_b=256,
    logging=ecs.GenericLogDriver(
        log_driver="fluentd",
        options={
            "tag": "example-tag"
        }
    )
)

Constructs a new instance of the GenericLogDriver class.

Parameters:
  • log_driver (str) – The log driver to use for the container. The valid values listed for this parameter are log drivers that the Amazon ECS container agent can communicate with by default. For tasks using the Fargate launch type, the supported log drivers are awslogs and splunk. For tasks using the EC2 launch type, the supported log drivers are awslogs, syslog, gelf, fluentd, splunk, journald, and json-file. For more information about using the awslogs log driver, see Using the awslogs Log Driver in the Amazon Elastic Container Service Developer Guide.

  • options (Optional[Mapping[str, str]]) – The configuration options to send to the log driver. Default: - the log driver options.

  • secret_options (Optional[Mapping[str, Secret]]) – The secrets to pass to the log configuration. Default: - no secret options provided.

Methods

bind(_scope, _container_definition)

Called when the log driver is configured on a container.

Parameters:
Return type:

LogDriverConfig

Static Methods

classmethod aws_logs(*, stream_prefix, datetime_format=None, log_group=None, log_retention=None, mode=None, multiline_pattern=None)

Creates a log driver configuration that sends log information to CloudWatch Logs.

Parameters:
  • stream_prefix (str) – Prefix for the log streams. The awslogs-stream-prefix option allows you to associate a log stream with the specified prefix, the container name, and the ID of the Amazon ECS task to which the container belongs. If you specify a prefix with this option, then the log stream takes the following format:: prefix-name/container-name/ecs-task-id

  • datetime_format (Optional[str]) – This option defines a multiline start pattern in Python strftime format. A log message consists of a line that matches the pattern and any following lines that don’t match the pattern. Thus the matched line is the delimiter between log messages. Default: - No multiline matching.

  • log_group (Optional[ILogGroup]) – The log group to log to. Default: - A log group is automatically created.

  • log_retention (Optional[RetentionDays]) – The number of days log events are kept in CloudWatch Logs when the log group is automatically created by this construct. Default: - Logs never expire.

  • mode (Optional[AwsLogDriverMode]) – The delivery mode of log messages from the container to awslogs. Default: - AwsLogDriverMode.BLOCKING

  • multiline_pattern (Optional[str]) – This option defines a multiline start pattern using a regular expression. A log message consists of a line that matches the pattern and any following lines that don’t match the pattern. Thus the matched line is the delimiter between log messages. This option is ignored if datetimeFormat is also configured. Default: - No multiline matching.

Return type:

LogDriver