mirror of
https://github.com/serverless/serverless.git
synced 2025-12-08 19:46:03 +00:00
feat: Support Lambda Logging Configuration (#12371)
This commit is contained in:
parent
5e604f2e1f
commit
0e465bd23c
@ -440,7 +440,7 @@ class AwsCompileFunctions {
|
||||
functionResource.Properties.ReservedConcurrentExecutions = functionObject.reservedConcurrency;
|
||||
}
|
||||
|
||||
if (!functionObject.disableLogs) {
|
||||
if (!functionObject.disableLogs && !functionObject?.logs?.logGroup && !this.serverless.service.provider.logs?.lambda?.logGroup) {
|
||||
functionResource.DependsOn = [this.provider.naming.getLogGroupLogicalId(functionName)].concat(
|
||||
functionResource.DependsOn || []
|
||||
);
|
||||
@ -629,10 +629,30 @@ class AwsCompileFunctions {
|
||||
}
|
||||
}
|
||||
|
||||
if (functionObject.logs || this.serverless.service.provider.logs.lambda) {
|
||||
const functionLogConfig = functionObject.logs
|
||||
const providerLogConfig = this.serverless.service.provider.logs.lambda
|
||||
const applicationLogLevel = functionLogConfig?.applicationLogLevel || providerLogConfig?.applicationLogLevel
|
||||
const logFormat = functionLogConfig?.logFormat || providerLogConfig?.logFormat
|
||||
const logGroup = functionLogConfig?.logGroup || providerLogConfig?.logGroup
|
||||
const systemLogLevel = functionLogConfig?.systemLogLevel || providerLogConfig?.systemLogLevel
|
||||
|
||||
const finalizedLogConfiguration = {}
|
||||
if (applicationLogLevel && logFormat && logFormat === 'JSON') { finalizedLogConfiguration.ApplicationLogLevel = applicationLogLevel }
|
||||
if (logFormat) { finalizedLogConfiguration.LogFormat = logFormat }
|
||||
if (logGroup) { finalizedLogConfiguration.LogFormat = logGroup }
|
||||
if (systemLogLevel && logFormat && logFormat === 'JSON') { finalizedLogConfiguration.SystemLogLevel = systemLogLevel }
|
||||
|
||||
if (Object.keys(finalizedLogConfiguration).length > 0) {
|
||||
functionResource.Properties.LoggingConfig = finalizedLogConfiguration
|
||||
}
|
||||
}
|
||||
|
||||
this.compileFunctionUrl(functionName);
|
||||
this.compileFunctionEventInvokeConfig(functionName);
|
||||
}
|
||||
|
||||
|
||||
compileFunctionUrl(functionName) {
|
||||
const functionObject = this.serverless.service.getFunction(functionName);
|
||||
const cfTemplate = this.serverless.service.provider.compiledCloudFormationTemplate;
|
||||
|
||||
@ -16,6 +16,9 @@ module.exports = {
|
||||
.filter((functionName) => !this.serverless.service.getFunction(functionName).disableLogs)
|
||||
.forEach((functionName) => {
|
||||
const functionObject = this.serverless.service.getFunction(functionName);
|
||||
if (functionObject.logs?.logGroup || this.serverless.service.provider.logs?.lambda?.logGroup) {
|
||||
return
|
||||
}
|
||||
const logGroupLogicalId = this.provider.naming.getLogGroupLogicalId(functionName);
|
||||
const newLogGroup = {
|
||||
[logGroupLogicalId]: {
|
||||
|
||||
@ -715,6 +715,19 @@ class AwsProvider {
|
||||
3288, 3653,
|
||||
],
|
||||
},
|
||||
awsLambdaLoggingConfiguration: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
applicationLogLevel: {
|
||||
type: 'string',
|
||||
enum: ['DEBUG', 'ERROR', 'FATAL', 'INFO', 'TRACE', 'WARN']
|
||||
},
|
||||
logFormat: { type: 'string', enum: ['JSON', 'TRACE']},
|
||||
logGroup: { type: 'string', pattern: '[\\.\\-_/#A-Za-z0-9]+', minLength: 1, maxLength: 512},
|
||||
systemLogLevel: { type: 'string', enum: ['DEBUG', 'INFO', 'WARN'] }
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
awsLogDataProtectionPolicy: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
@ -1163,6 +1176,7 @@ class AwsProvider {
|
||||
type: 'object',
|
||||
properties: {
|
||||
frameworkLambda: { type: 'boolean' },
|
||||
lambda: { $ref: '#/definitions/awsLambdaLoggingConfiguration' },
|
||||
httpApi: {
|
||||
anyOf: [
|
||||
{ type: 'boolean' },
|
||||
@ -1443,6 +1457,9 @@ class AwsProvider {
|
||||
logDataProtectionPolicy: {
|
||||
$ref: '#/definitions/awsLogDataProtectionPolicy',
|
||||
},
|
||||
logs: {
|
||||
$ref: '#/definitions/awsLambdaLoggingConfiguration'
|
||||
},
|
||||
maximumEventAge: { type: 'integer', minimum: 60, maximum: 21600 },
|
||||
maximumRetryAttempts: { type: 'integer', minimum: 0, maximum: 2 },
|
||||
memorySize: { $ref: '#/definitions/awsLambdaMemorySize' },
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user