LogDrivers

class aws_cdk.aws_ecs.LogDrivers

Bases: object

The base class for log drivers.

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.LogDrivers.aws_logs(stream_prefix="EventDemo")
)

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

classmethod firelens(*, options=None, secret_options=None, env=None, env_regex=None, labels=None, tag=None)

Creates a log driver configuration that sends log information to firelens log router.

For detail configurations, please refer to Amazon ECS FireLens Examples: https://github.com/aws-samples/amazon-ecs-firelens-examples

Parameters:
  • 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.

  • env (Optional[Sequence[str]]) – The env option takes an array of keys. If there is collision between label and env keys, the value of the env takes precedence. Adds additional fields to the extra attributes of a logging message. Default: - No env

  • env_regex (Optional[str]) – The env-regex option is similar to and compatible with env. Its value is a regular expression to match logging-related environment variables. It is used for advanced log tag options. Default: - No envRegex

  • labels (Optional[Sequence[str]]) – The labels option takes an array of keys. If there is collision between label and env keys, the value of the env takes precedence. Adds additional fields to the extra attributes of a logging message. Default: - No labels

  • tag (Optional[str]) – By default, Docker uses the first 12 characters of the container ID to tag log messages. Refer to the log tag option documentation for customizing the log tag format. Default: - The first 12 characters of the container ID

Return type:

LogDriver

classmethod fluentd(*, address=None, async_connect=None, buffer_limit=None, max_retries=None, retry_wait=None, sub_second_precision=None, env=None, env_regex=None, labels=None, tag=None)

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

Parameters:
  • address (Optional[str]) – By default, the logging driver connects to localhost:24224. Supply the address option to connect to a different address. tcp(default) and unix sockets are supported. Default: - address not set.

  • async_connect (Optional[bool]) – Docker connects to Fluentd in the background. Messages are buffered until the connection is established. Default: - false

  • buffer_limit (Union[int, float, None]) – The amount of data to buffer before flushing to disk. Default: - The amount of RAM available to the container.

  • max_retries (Union[int, float, None]) – The maximum number of retries. Default: - 4294967295 (2**32 - 1).

  • retry_wait (Optional[Duration]) – How long to wait between retries. Default: - 1 second

  • sub_second_precision (Optional[bool]) – Generates event logs in nanosecond resolution. Default: - false

  • env (Optional[Sequence[str]]) – The env option takes an array of keys. If there is collision between label and env keys, the value of the env takes precedence. Adds additional fields to the extra attributes of a logging message. Default: - No env

  • env_regex (Optional[str]) – The env-regex option is similar to and compatible with env. Its value is a regular expression to match logging-related environment variables. It is used for advanced log tag options. Default: - No envRegex

  • labels (Optional[Sequence[str]]) – The labels option takes an array of keys. If there is collision between label and env keys, the value of the env takes precedence. Adds additional fields to the extra attributes of a logging message. Default: - No labels

  • tag (Optional[str]) – By default, Docker uses the first 12 characters of the container ID to tag log messages. Refer to the log tag option documentation for customizing the log tag format. Default: - The first 12 characters of the container ID

Return type:

LogDriver

classmethod gelf(*, address, compression_level=None, compression_type=None, tcp_max_reconnect=None, tcp_reconnect_delay=None, env=None, env_regex=None, labels=None, tag=None)

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

Parameters:
  • address (str) – The address of the GELF server. tcp and udp are the only supported URI specifier and you must specify the port.

  • compression_level (Union[int, float, None]) – UDP Only The level of compression when gzip or zlib is the gelf-compression-type. An integer in the range of -1 to 9 (BestCompression). Higher levels provide more compression at lower speed. Either -1 or 0 disables compression. Default: - 1

  • compression_type (Optional[GelfCompressionType]) – UDP Only The type of compression the GELF driver uses to compress each log message. Allowed values are gzip, zlib and none. Default: - gzip

  • tcp_max_reconnect (Union[int, float, None]) – TCP Only The maximum number of reconnection attempts when the connection drop. A positive integer. Default: - 3

  • tcp_reconnect_delay (Optional[Duration]) – TCP Only The number of seconds to wait between reconnection attempts. A positive integer. Default: - 1

  • env (Optional[Sequence[str]]) – The env option takes an array of keys. If there is collision between label and env keys, the value of the env takes precedence. Adds additional fields to the extra attributes of a logging message. Default: - No env

  • env_regex (Optional[str]) – The env-regex option is similar to and compatible with env. Its value is a regular expression to match logging-related environment variables. It is used for advanced log tag options. Default: - No envRegex

  • labels (Optional[Sequence[str]]) – The labels option takes an array of keys. If there is collision between label and env keys, the value of the env takes precedence. Adds additional fields to the extra attributes of a logging message. Default: - No labels

  • tag (Optional[str]) – By default, Docker uses the first 12 characters of the container ID to tag log messages. Refer to the log tag option documentation for customizing the log tag format. Default: - The first 12 characters of the container ID

Return type:

LogDriver

classmethod journald(*, env=None, env_regex=None, labels=None, tag=None)

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

Parameters:
  • env (Optional[Sequence[str]]) – The env option takes an array of keys. If there is collision between label and env keys, the value of the env takes precedence. Adds additional fields to the extra attributes of a logging message. Default: - No env

  • env_regex (Optional[str]) – The env-regex option is similar to and compatible with env. Its value is a regular expression to match logging-related environment variables. It is used for advanced log tag options. Default: - No envRegex

  • labels (Optional[Sequence[str]]) – The labels option takes an array of keys. If there is collision between label and env keys, the value of the env takes precedence. Adds additional fields to the extra attributes of a logging message. Default: - No labels

  • tag (Optional[str]) – By default, Docker uses the first 12 characters of the container ID to tag log messages. Refer to the log tag option documentation for customizing the log tag format. Default: - The first 12 characters of the container ID

Return type:

LogDriver

classmethod json_file(*, compress=None, max_file=None, max_size=None, env=None, env_regex=None, labels=None, tag=None)

Creates a log driver configuration that sends log information to json-file Logs.

Parameters:
  • compress (Optional[bool]) – Toggles compression for rotated logs. Default: - false

  • max_file (Union[int, float, None]) – The maximum number of log files that can be present. If rolling the logs creates excess files, the oldest file is removed. Only effective when max-size is also set. A positive integer. Default: - 1

  • max_size (Optional[str]) – The maximum size of the log before it is rolled. A positive integer plus a modifier representing the unit of measure (k, m, or g). Default: - -1 (unlimited)

  • env (Optional[Sequence[str]]) – The env option takes an array of keys. If there is collision between label and env keys, the value of the env takes precedence. Adds additional fields to the extra attributes of a logging message. Default: - No env

  • env_regex (Optional[str]) – The env-regex option is similar to and compatible with env. Its value is a regular expression to match logging-related environment variables. It is used for advanced log tag options. Default: - No envRegex

  • labels (Optional[Sequence[str]]) – The labels option takes an array of keys. If there is collision between label and env keys, the value of the env takes precedence. Adds additional fields to the extra attributes of a logging message. Default: - No labels

  • tag (Optional[str]) – By default, Docker uses the first 12 characters of the container ID to tag log messages. Refer to the log tag option documentation for customizing the log tag format. Default: - The first 12 characters of the container ID

Return type:

LogDriver

classmethod splunk(*, url, ca_name=None, ca_path=None, format=None, gzip=None, gzip_level=None, index=None, insecure_skip_verify=None, secret_token=None, source=None, source_type=None, token=None, verify_connection=None, env=None, env_regex=None, labels=None, tag=None)

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

Parameters:
  • url (str) – Path to your Splunk Enterprise, self-service Splunk Cloud instance, or Splunk Cloud managed cluster (including port and scheme used by HTTP Event Collector) in one of the following formats: https://your_splunk_instance:8088 or https://input-prd-p-XXXXXXX.cloud.splunk.com:8088 or https://http-inputs-XXXXXXXX.splunkcloud.com.

  • ca_name (Optional[str]) – Name to use for validating server certificate. Default: - The hostname of the splunk-url

  • ca_path (Optional[str]) – Path to root certificate. Default: - caPath not set.

  • format (Optional[SplunkLogFormat]) – Message format. Can be inline, json or raw. Default: - inline

  • gzip (Optional[bool]) – Enable/disable gzip compression to send events to Splunk Enterprise or Splunk Cloud instance. Default: - false

  • gzip_level (Union[int, float, None]) – Set compression level for gzip. Valid values are -1 (default), 0 (no compression), 1 (best speed) … 9 (best compression). Default: - -1 (Default Compression)

  • index (Optional[str]) – Event index. Default: - index not set.

  • insecure_skip_verify (Optional[str]) – Ignore server certificate validation. Default: - insecureSkipVerify not set.

  • secret_token (Optional[Secret]) – Splunk HTTP Event Collector token (Secret). The splunk-token is added to the SecretOptions property of the Log Driver Configuration. So the secret value will not be resolved or viewable as plain text. Please provide at least one of token or secretToken. Default: - If secret token is not provided, then the value provided in token will be used.

  • source (Optional[str]) – Event source. Default: - source not set.

  • source_type (Optional[str]) – Event source type. Default: - sourceType not set.

  • token (Optional[SecretValue]) – (deprecated) Splunk HTTP Event Collector token. The splunk-token is added to the Options property of the Log Driver Configuration. So the secret value will be resolved and viewable in plain text in the console. Please provide at least one of token or secretToken. Default: - token not provided.

  • verify_connection (Optional[bool]) – Verify on start, that docker can connect to Splunk server. Default: - true

  • env (Optional[Sequence[str]]) – The env option takes an array of keys. If there is collision between label and env keys, the value of the env takes precedence. Adds additional fields to the extra attributes of a logging message. Default: - No env

  • env_regex (Optional[str]) – The env-regex option is similar to and compatible with env. Its value is a regular expression to match logging-related environment variables. It is used for advanced log tag options. Default: - No envRegex

  • labels (Optional[Sequence[str]]) – The labels option takes an array of keys. If there is collision between label and env keys, the value of the env takes precedence. Adds additional fields to the extra attributes of a logging message. Default: - No labels

  • tag (Optional[str]) – By default, Docker uses the first 12 characters of the container ID to tag log messages. Refer to the log tag option documentation for customizing the log tag format. Default: - The first 12 characters of the container ID

Return type:

LogDriver

classmethod syslog(*, address=None, facility=None, format=None, tls_ca_cert=None, tls_cert=None, tls_key=None, tls_skip_verify=None, env=None, env_regex=None, labels=None, tag=None)

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

Parameters:
  • address (Optional[str]) – The address of an external syslog server. The URI specifier may be [tcp|udp|tcp+tls]://host:port, unix://path, or unixgram://path. Default: - If the transport is tcp, udp, or tcp+tls, the default port is 514.

  • facility (Optional[str]) – The syslog facility to use. Can be the number or name for any valid syslog facility. See the syslog documentation: https://tools.ietf.org/html/rfc5424#section-6.2.1. Default: - facility not set

  • format (Optional[str]) – The syslog message format to use. If not specified the local UNIX syslog format is used, without a specified hostname. Specify rfc3164 for the RFC-3164 compatible format, rfc5424 for RFC-5424 compatible format, or rfc5424micro for RFC-5424 compatible format with microsecond timestamp resolution. Default: - format not set

  • tls_ca_cert (Optional[str]) – The absolute path to the trust certificates signed by the CA. Ignored if the address protocol is not tcp+tls. Default: - tlsCaCert not set

  • tls_cert (Optional[str]) – The absolute path to the TLS certificate file. Ignored if the address protocol is not tcp+tls. Default: - tlsCert not set

  • tls_key (Optional[str]) – The absolute path to the TLS key file. Ignored if the address protocol is not tcp+tls. Default: - tlsKey not set

  • tls_skip_verify (Optional[bool]) – If set to true, TLS verification is skipped when connecting to the syslog daemon. Ignored if the address protocol is not tcp+tls. Default: - false

  • env (Optional[Sequence[str]]) – The env option takes an array of keys. If there is collision between label and env keys, the value of the env takes precedence. Adds additional fields to the extra attributes of a logging message. Default: - No env

  • env_regex (Optional[str]) – The env-regex option is similar to and compatible with env. Its value is a regular expression to match logging-related environment variables. It is used for advanced log tag options. Default: - No envRegex

  • labels (Optional[Sequence[str]]) – The labels option takes an array of keys. If there is collision between label and env keys, the value of the env takes precedence. Adds additional fields to the extra attributes of a logging message. Default: - No labels

  • tag (Optional[str]) – By default, Docker uses the first 12 characters of the container ID to tag log messages. Refer to the log tag option documentation for customizing the log tag format. Default: - The first 12 characters of the container ID

Return type:

LogDriver