Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/guides/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,33 @@ functions:
ephemeralStorageSize: 1024
```

## Logging Configuration

[Configuring Lambda advanced logging options](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs.html#monitoring-cloudwatchlogs-advanced)

This can be configured at the provider level (applies to all functions) or individually per function:

```yml
# Provider-level configuration (applies to all functions)
provider:
logs:
lambda:
logFormat: JSON
applicationLogLevel: INFO
systemLogLevel: WARN
logGroup: /aws/lambda/global-log-group

# Function-level configuration (overrides provider settings)
functions:
helloLogging:
handler: handler.handler
logs:
applicationLogLevel: DEBUG
logFormat: JSON
logGroup: helloLoggingLogGroup
systemLogLevel: DEBUG
```

## Lambda Hashing Algorithm migration

**Note** Below migration guide is intended to be used if you are already using `v3` version of the Framework and you have `provider.lambdaHashingVersion` property set to `20200924` in your configuration file. If you are still on v2 and want to upgrade to v3, please refer to [V3 Upgrade docs](../../../guides/upgrading-v3.md#lambda-hashing-algorithm).
Expand Down
17 changes: 17 additions & 0 deletions docs/guides/serverless.yml.md
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,17 @@ Configure logs for the deployed resources:
```yml
provider:
logs:
# Optional Configuration of Lambda Logging Configuration
lambda:
# The Log Format to be used for all lambda functions (default: Text)
logFormat: JSON
# The Application Log Level to be used, This can only be set if `logFormat` is set to `JSON`
applicationLogLevel: ERROR
# The System Log Level to be used, This can only be set if `logFormat` is set to `JSON`
systemLogLevel: INFO
# The LogGroup that will be used by default. If this is set the Framework will not create LogGroups for any functions
logGroup: /aws/lambda/global-log-group

# Enable HTTP API logs
# This can either be set to `httpApi: true` to use defaults, or configured via subproperties
# Can only be configured if the API is created by Serverless Framework
Expand Down Expand Up @@ -722,6 +733,12 @@ functions:
maximumRetryAttempts: 1
# Maximum event age in seconds when invoking asynchronously (between 60 and 21600)
maximumEventAge: 7200
# Configuring Lambda advanced logging options
logs:
applicationLogLevel: DEBUG
logFormat: JSON
logGroup: helloLoggingLogGroup
systemLogLevel: DEBUG
```

## Lambda events
Expand Down
28 changes: 28 additions & 0 deletions lib/plugins/aws/package/compile/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,34 @@ class AwsCompileFunctions {
}
}

const logs =
functionObject.logs ||
(this.serverless.service.provider.logs && this.serverless.service.provider.logs.lambda);

if (logs) {
const loggingConfig = {};

if (logs.applicationLogLevel) {
loggingConfig.ApplicationLogLevel = logs.applicationLogLevel;
}

if (logs.logFormat) {
loggingConfig.LogFormat = logs.logFormat;
}

if (logs.logGroup) {
loggingConfig.LogGroup = logs.logGroup;
}

if (logs.systemLogLevel) {
loggingConfig.SystemLogLevel = logs.systemLogLevel;
}

if (Object.keys(loggingConfig).length) {
functionResource.Properties.LoggingConfig = loggingConfig;
}
}

this.compileFunctionUrl(functionName);
this.compileFunctionEventInvokeConfig(functionName);
}
Expand Down
26 changes: 26 additions & 0 deletions lib/plugins/aws/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,19 @@ class AwsProvider {
},
],
},
lambda: {
type: 'object',
properties: {
applicationLogLevel: {
type: 'string',
enum: ['DEBUG', 'ERROR', 'FATAL', 'INFO', 'TRACE', 'WARN'],
},
logFormat: { type: 'string', enum: ['JSON', 'Text'] },
logGroup: { type: 'string', pattern: '^[.\\-_/#A-Za-z0-9]{1,512}$' },
systemLogLevel: { type: 'string', enum: ['DEBUG', 'INFO', 'WARN'] },
},
additionalProperties: false,
},
},
},
memorySize: { $ref: '#/definitions/awsLambdaMemorySize' },
Expand Down Expand Up @@ -1394,6 +1407,19 @@ class AwsProvider {
disableLogs: { type: 'boolean' },
environment: { $ref: '#/definitions/awsLambdaEnvironment' },
ephemeralStorageSize: { type: 'integer', minimum: 512, maximum: 10240 },
logs: {
type: 'object',
properties: {
applicationLogLevel: {
type: 'string',
enum: ['DEBUG', 'ERROR', 'FATAL', 'INFO', 'TRACE', 'WARN'],
},
logFormat: { type: 'string', enum: ['JSON', 'Text'] },
logGroup: { type: 'string', pattern: '^[.\\-_/#A-Za-z0-9]{1,512}$' },
systemLogLevel: { type: 'string', enum: ['DEBUG', 'INFO', 'WARN'] },
},
additionalProperties: false,
},
fileSystemConfig: {
type: 'object',
properties: {
Expand Down
Loading