Skip to content
v2.277.0

LoggingFormat Enum ​

This field takes in 2 values either Text or JSON.

By setting this value to Text, will result in the current structure of logs format, whereas, by setting this value to JSON, Lambda will print the logs as Structured JSON Logs, with the corresponding timestamp and log level of each event. Selecting ‘JSON’ format will only allow customers to have different log level Application log level and the System log level.

Example ​

ts
import { ILogGroup } from 'aws-cdk-lib/aws-logs';

declare const logGroup: ILogGroup;

new lambda.Function(this, 'Lambda', {
  code: new lambda.InlineCode('foo'),
  handler: 'index.handler',
  runtime: lambda.Runtime.NODEJS_LATEST,
  loggingFormat: lambda.LoggingFormat.JSON,
  systemLogLevelV2: lambda.SystemLogLevel.INFO,
  applicationLogLevelV2: lambda.ApplicationLogLevel.INFO,
  logGroup: logGroup,
});
python
from aws_cdk.aws_logs import ILogGroup

# log_group: ILogGroup


lambda_.Function(self, "Lambda",
    code=lambda_.InlineCode("foo"),
    handler="index.handler",
    runtime=lambda_.Runtime.NODEJS_LATEST,
    logging_format=lambda_.LoggingFormat.JSON,
    system_log_level_v2=lambda_.SystemLogLevel.INFO,
    application_log_level_v2=lambda_.ApplicationLogLevel.INFO,
    log_group=log_group
)
java
import software.amazon.awscdk.services.logs.ILogGroup;

ILogGroup logGroup;


Function.Builder.create(this, "Lambda")
        .code(new InlineCode("foo"))
        .handler("index.handler")
        .runtime(Runtime.NODEJS_LATEST)
        .loggingFormat(LoggingFormat.JSON)
        .systemLogLevelV2(SystemLogLevel.INFO)
        .applicationLogLevelV2(ApplicationLogLevel.INFO)
        .logGroup(logGroup)
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.Logs;

ILogGroup logGroup;


new Function(this, "Lambda", new FunctionProps {
    Code = new InlineCode("foo"),
    Handler = "index.handler",
    Runtime = Runtime.NODEJS_LATEST,
    LoggingFormat = LoggingFormat.JSON,
    SystemLogLevelV2 = SystemLogLevel.INFO,
    ApplicationLogLevelV2 = ApplicationLogLevel.INFO,
    LogGroup = logGroup
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"

var logGroup ILogGroup


lambda.NewFunction(this, jsii.String("Lambda"), &FunctionProps{
	Code: lambda.NewInlineCode(jsii.String("foo")),
	Handler: jsii.String("index.handler"),
	Runtime: lambda.Runtime_NODEJS_LATEST(),
	LoggingFormat: lambda.LoggingFormat_JSON,
	SystemLogLevelV2: lambda.SystemLogLevel_INFO,
	ApplicationLogLevelV2: lambda.ApplicationLogLevel_INFO,
	LogGroup: logGroup,
})

Members ​

MemberDescription
TEXTLambda Logs text format.
JSONLambda structured logging in Json format.

Referenced by ​

  • FunctionOptions.loggingFormatlogging_formatloggingFormatLoggingFormatLoggingFormat