Class AccessLogFormat
- Namespace
- Amazon.CDK.AWS.APIGateway
- Assembly
- Amazon.CDK.AWS.APIGateway.dll
factory methods for access log format.
public class AccessLogFormat : DeputyBase
- Inheritance
-
AccessLogFormat
Examples
var logGroup = new LogGroup(this, "ApiGatewayAccessLogs");
new RestApi(this, "books", new RestApiProps {
DeployOptions = new StageOptions {
AccessLogDestination = new LogGroupLogDestination(logGroup),
AccessLogFormat = AccessLogFormat.Custom($"{apigateway.AccessLogField.contextRequestId()} {apigateway.AccessLogField.contextErrorMessage()} {apigateway.AccessLogField.contextErrorMessageString()}")
}
});
Remarks
ExampleMetadata: infused
Methods
Clf()
Generate Common Log Format.
public static AccessLogFormat Clf()
Returns
Custom(string)
Custom log format.
public static AccessLogFormat Custom(string format)
Parameters
format
string
Returns
Examples
AccessLogFormat.Custom(JSON.Stringify(new Dictionary<string, object> {
{ "requestId", AccessLogField.ContextRequestId() },
{ "sourceIp", AccessLogField.ContextIdentitySourceIp() },
{ "method", AccessLogField.ContextHttpMethod() },
{ "userContext", new Struct {
Sub = AccessLogField.ContextAuthorizerClaims("sub"),
Email = AccessLogField.ContextAuthorizerClaims("email")
} }
}));
Remarks
You can create any log format string. You can easily get the $ context variable by using the methods of AccessLogField.
JsonWithStandardFields(IJsonWithStandardFieldProps?)
Access log will be produced in the JSON format with a set of fields most useful in the access log.
public static AccessLogFormat JsonWithStandardFields(IJsonWithStandardFieldProps? fields = null)
Parameters
fields
IJsonWithStandardFieldProps
Returns
Remarks
All fields are turned on by default with the option to turn off specific fields.
ToString()
Output a format string to be used with CloudFormation.
public override string ToString()