Skip to content

Conversation

@jimmyn
Copy link
Contributor

@jimmyn jimmyn commented Oct 27, 2025

Summary

Implements AWS Lambda advanced logging configuration support as requested in serverless/serverless#12264. This feature enables developers to configure JSON-formatted logs, application log levels, system log levels, and custom log groups for Lambda functions at both provider and function levels.

Related to serverless/serverless#12315 (originally targeting v3 branch).

Based on AWS announcement: https://aws.amazon.com/blogs/compute/introducing-advanced-logging-controls-for-aws-lambda-functions/

Implementation

  • Schema validation (lib/plugins/aws/provider.js):

    • Added provider.logs.lambda configuration with validation for:
      • applicationLogLevel: DEBUG, ERROR, FATAL, INFO, TRACE, WARN
      • logFormat: JSON, Text
      • logGroup: Custom log group path (1-512 characters)
      • systemLogLevel: DEBUG, INFO, WARN
    • Added function-level logs property with same schema
    • Function-level configuration overrides provider-level configuration
  • CloudFormation compilation (lib/plugins/aws/package/compile/functions.js):

    • Implements inheritance: function logs override provider.logs.lambda
    • Converts YAML logs config to CloudFormation LoggingConfig property with proper PascalCase mapping
  • Documentation:

    • Updated functions.md with provider and function-level examples
    • Updated serverless.yml.md with provider.logs.lambda configuration
    • Shows inheritance behavior clearly
  • Comprehensive testing (373 lines total):

    • Tests for all valid/invalid values at function level
    • Tests for provider-level configuration
    • Tests for function-level overriding provider-level
    • CloudFormation output verification

Configuration Examples

Provider-level (applies to all functions):

provider:
  logs:
    lambda:
      logFormat: JSON
      applicationLogLevel: INFO
      systemLogLevel: WARN
      logGroup: /aws/lambda/global-log-group

Function-level (overrides provider):

functions:
  hello:
    handler: handler.handler
    logs:
      applicationLogLevel: DEBUG
      logFormat: JSON
      logGroup: /aws/lambda/custom-log-group
      systemLogLevel: DEBUG

Test Plan

  • Schema validation tests for all applicationLogLevel values (DEBUG, ERROR, FATAL, INFO, TRACE, WARN)
  • Schema validation tests for all logFormat values (JSON, Text)
  • Schema validation tests for all systemLogLevel values (DEBUG, INFO, WARN)
  • Invalid value rejection tests
  • Provider-level logs.lambda configuration test
  • Function-level overrides provider-level test
  • CloudFormation LoggingConfig property generation
  • Integration with existing function compilation
  • All 23 logging-related tests passing

Closes serverless/serverless#12264
Related: serverless/serverless#12315

- Add logs property to function schema with applicationLogLevel, logFormat, logGroup, systemLogLevel
- Implement LoggingConfig compilation in functions.js
- Add comprehensive tests for all log level values and validation
- Update documentation with examples

Enables AWS Lambda advanced logging controls including JSON format logs,
custom log levels, and custom log groups as announced in:
https://aws.amazon.com/blogs/compute/introducing-advanced-logging-controls-for-aws-lambda-functions/

Closes #12264
- Add provider.logs.lambda schema with same properties as function-level
- Implement inheritance: function logs override provider logs
- Add tests for provider-level config and override behavior
- Update docs to show both provider and function-level examples
- Fix logGroup pattern to properly escape dash character

Functions without explicit logs config now inherit from provider.logs.lambda
if configured, matching behavior of other provider-level properties like
tracing and kmsKeyArn.
@mnapoli
Copy link
Contributor

mnapoli commented Oct 28, 2025

Thanks!

@mnapoli mnapoli merged commit 43d1dc1 into oss-serverless:main Oct 28, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable LoggingConfig configuration on Lambda Functions

2 participants