Skip to content
v2.278.0

LogDriver Class ​

The base class for log drivers.

Example ​

ts
declare const secret: ecs.Secret;

// Create a Task Definition for the container to start
const taskDefinition = new ecs.Ec2TaskDefinition(this, 'TaskDef');
taskDefinition.addContainer('TheContainer', {
  image: ecs.ContainerImage.fromRegistry('example-image'),
  memoryLimitMiB: 256,
  logging: ecs.LogDrivers.splunk({
    secretToken: secret,
    url: 'my-splunk-url',
  }),
});
python
# secret: ecs.Secret


# 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.splunk(
        secret_token=secret,
        url="my-splunk-url"
    )
)
java
Secret secret;


// Create a Task Definition for the container to start
Ec2TaskDefinition taskDefinition = new Ec2TaskDefinition(this, "TaskDef");
taskDefinition.addContainer("TheContainer", ContainerDefinitionOptions.builder()
        .image(ContainerImage.fromRegistry("example-image"))
        .memoryLimitMiB(256)
        .logging(LogDrivers.splunk(SplunkLogDriverProps.builder()
                .secretToken(secret)
                .url("my-splunk-url")
                .build()))
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
Secret secret;


// Create a Task Definition for the container to start
var taskDefinition = new Ec2TaskDefinition(this, "TaskDef");
taskDefinition.AddContainer("TheContainer", new ContainerDefinitionOptions {
    Image = ContainerImage.FromRegistry("example-image"),
    MemoryLimitMiB = 256,
    Logging = LogDrivers.Splunk(new SplunkLogDriverProps {
        SecretToken = secret,
        Url = "my-splunk-url"
    })
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var secret Secret


// Create a Task Definition for the container to start
taskDefinition := ecs.NewEc2TaskDefinition(this, jsii.String("TaskDef"))
taskDefinition.AddContainer(jsii.String("TheContainer"), &ContainerDefinitionOptions{
	Image: ecs.ContainerImage_FromRegistry(jsii.String("example-image")),
	MemoryLimitMiB: jsii.Number(256),
	Logging: ecs.LogDrivers_Splunk(&SplunkLogDriverProps{
		SecretToken: secret,
		Url: jsii.String("my-splunk-url"),
	}),
})

Initializer ​

ts
new LogDriver()
python
LogDriver()
java
new LogDriver()
csharp
new LogDriver()
go
NewLogDriver()

Methods ​

awsLogs(props: AwsLogDriverProps): LogDriver // chainable@staticmethod def aws_logs(props: AwsLogDriverProps) -> LogDriverpublic static LogDriver awsLogs(AwsLogDriverProps props)public static LogDriver AwsLogs(AwsLogDriverProps props)func AwsLogs(Props AwsLogDriverProps) LogDriver static #
Creates a log driver configuration that sends log information to CloudWatch Logs.
bind(scope: Construct, containerDefinition: ContainerDefinition): LogDriverConfigdef bind(self, scope: Construct, container_definition: ContainerDefinition) -> LogDriverConfigpublic LogDriverConfig bind(Construct scope, ContainerDefinition containerDefinition)public LogDriverConfig Bind(Construct scope, ContainerDefinition containerDefinition)func Bind(Scope Construct, ContainerDefinition ContainerDefinition) LogDriverConfig #
Called when the log driver is configured on a container.