Skip to content

Commit 179a2ff

Browse files
committed
fix response log format issue
1 parent 9de0c79 commit 179a2ff

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

LambdaEnvironment.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ final class LambdaEnvironment(
8383
final val shouldLogInJsonArrayFormat: Boolean =
8484
maybeGetProperty("LAMBDA_RUNTIME_LOG_FORMAT")
8585
.map(_.toUpperCase().contains("JSON_ARRAY"))
86-
.getOrElse(false)
86+
.getOrElse(true)
8787

8888
final val shouldLogInJsonStringFormat: Boolean =
8989
maybeGetProperty("LAMBDA_RUNTIME_LOG_FORMAT")

LambdaRuntime.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,14 @@ trait LambdaRuntime extends EventHandler, EventHandlerTag {
356356
}
357357
)
358358

359+
val t1 = System.currentTimeMillis()
360+
359361
val output = result.fold(identity, identity)
360362

361363
val isJsonReponse =
362364
(output.startsWith("{") && output.endsWith("}"))
363365
|| (output.startsWith("[") && output.endsWith("]"))
364366

365-
val t1 = System.currentTimeMillis()
366-
367367
// https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format_Specification.html
368368
val awsEmbededMetric =
369369
s""""_aws":{"Timestamp":$t1,"CloudWatchMetrics":[{"Namespace":"lambda-${functionName}-metrics","Dimensions":[${
@@ -388,7 +388,7 @@ trait LambdaRuntime extends EventHandler, EventHandlerTag {
388388
.getRuntime()
389389
.maxMemory()},"totalMemory":${Runtime
390390
.getRuntime()
391-
.totalMemory()},"freeMemory":${Runtime.getRuntime().freeMemory()},$awsEmbededMetric,}"""
391+
.totalMemory()},"freeMemory":${Runtime.getRuntime().freeMemory()},$awsEmbededMetric}"""
392392
else {
393393
s"[$id]$tag ${RESPONSE}LAMBDA RESPONSE [${t1 - t0}ms] ${AnsiColor.BOLD}$output"
394394
}

0 commit comments

Comments
 (0)