# AccessLogFormat

factory methods for access log format.

- Source: [`aws-apigateway/lib/access-log.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-apigateway/lib/access-log.ts#L728)
- Type last changed: v2.222.0 · 4 Nov 2025

## Example

```ts
const destinationBucket = new s3.Bucket(this, 'Bucket');
const deliveryStreamRole = new iam.Role(this, 'Role', {
  assumedBy: new iam.ServicePrincipal('firehose.amazonaws.com'),
});

const stream = new firehose.CfnDeliveryStream(this, 'MyStream', {
  deliveryStreamName: 'amazon-apigateway-delivery-stream',
  s3DestinationConfiguration: {
    bucketArn: destinationBucket.bucketArn,
    roleArn: deliveryStreamRole.roleArn,
  },
});

const api = new apigateway.RestApi(this, 'books', {
  deployOptions: {
    accessLogDestination: new apigateway.FirehoseLogDestination(stream),
    accessLogFormat: apigateway.AccessLogFormat.jsonWithStandardFields(),
  },
});
```

## Initializer

```ts
new AccessLogFormat(format: string)
```

## Methods

- `clf(): AccessLogFormat // chainable` (static) — Generate Common Log Format.

- `custom(format: string): AccessLogFormat // chainable` (static) — Custom log format.

  You can create any log format string. You can easily get the $ context variable by using the methods of AccessLogField.

  ```ts
   apigateway.AccessLogFormat.custom(JSON.stringify({
       requestId: apigateway.AccessLogField.contextRequestId(),
       sourceIp: apigateway.AccessLogField.contextIdentitySourceIp(),
       method: apigateway.AccessLogField.contextHttpMethod(),
       userContext: {
         sub: apigateway.AccessLogField.contextAuthorizerClaims('sub'),
         email: apigateway.AccessLogField.contextAuthorizerClaims('email')
       }
    }))
  ```

- `jsonWithStandardFields(fields?: JsonWithStandardFieldProps): AccessLogFormat // chainable` (static) — Access log will be produced in the JSON format with a set of fields most useful in the access log.

  All fields are turned on by default with the
  option to turn off specific fields.

- `toString(): string` — Output a format string to be used with CloudFormation.
