mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
Add a logFormat property
This commit is contained in:
parent
8d629552dd
commit
a2b60c3429
@ -1495,12 +1495,13 @@ By default, API Gateway access logs will use the following format:
|
||||
'requestId: $context.requestId, ip: $context.identity.sourceIp, caller: $context.identity.caller, user: $context.identity.user, requestTime: $context.requestTime, httpMethod: $context.httpMethod, resourcePath: $context.resourcePath, status: $context.status, protocol: $context.protocol, responseLength: $context.responseLength'
|
||||
```
|
||||
|
||||
You can specify your own [format for API Gateway Access Logs](https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-logging.html#apigateway-cloudwatch-log-formats) by including your preferred string as a value to `restApi`:
|
||||
You can specify your own [format for API Gateway Access Logs](https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-logging.html#apigateway-cloudwatch-log-formats) by including your preferred string in the `logFormat` property:
|
||||
|
||||
```yml
|
||||
# serverless.yml
|
||||
provider:
|
||||
name: aws
|
||||
logs:
|
||||
restApi: '{ "requestId":"$context.requestId", "ip": "$context.identity.sourceIp" }'
|
||||
restApi:
|
||||
logFormat: '{ "requestId":"$context.requestId", "ip": "$context.identity.sourceIp" }'
|
||||
```
|
||||
@ -186,9 +186,10 @@ function handleLogs() {
|
||||
const region = this.options.region;
|
||||
const logGroupName = `/aws/api-gateway/${service}-${stage}`;
|
||||
|
||||
const logFormat = provider.logs.restApi === true
|
||||
? defaultApiGatewayLogFormat
|
||||
: provider.logs.restApi;
|
||||
let logFormat = defaultApiGatewayLogFormat;
|
||||
if (provider.logs.restApi.logFormat) {
|
||||
logFormat = provider.logs.restApi.logFormat;
|
||||
}
|
||||
|
||||
const destinationArn = {
|
||||
op: 'replace',
|
||||
|
||||
@ -338,7 +338,9 @@ describe('#updateStage()', () => {
|
||||
|
||||
it('should update the stage with a custom APIGW log format if given', () => {
|
||||
context.state.service.provider.logs = {
|
||||
restApi: 'requestId: $context.requestId',
|
||||
restApi: {
|
||||
logFormat: 'requestId: $context.requestId',
|
||||
},
|
||||
};
|
||||
|
||||
return updateStage.call(context).then(() => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user