File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,12 +15,6 @@ import (
1515 "strconv"
1616)
1717
18- // LogFormat is the log format, either TEXT or JSON (from AWS_LAMBDA_LOG_FORMAT)
19- var LogFormat string
20-
21- // LogLevel is the log level for structured logging (from AWS_LAMBDA_LOG_LEVEL). Only available when LogFormat is JSON
22- var LogLevel string
23-
2418// LogGroupName is the name of the log group that contains the log streams of the current Lambda Function
2519var LogGroupName string
2620
@@ -39,8 +33,6 @@ var FunctionVersion string
3933var maxConcurrency int
4034
4135func init () {
42- LogFormat = os .Getenv ("AWS_LAMBDA_LOG_FORMAT" )
43- LogLevel = os .Getenv ("AWS_LAMBDA_LOG_LEVEL" )
4436 LogGroupName = os .Getenv ("AWS_LAMBDA_LOG_GROUP_NAME" )
4537 LogStreamName = os .Getenv ("AWS_LAMBDA_LOG_STREAM_NAME" )
4638 FunctionName = os .Getenv ("AWS_LAMBDA_FUNCTION_NAME" )
Original file line number Diff line number Diff line change @@ -11,6 +11,12 @@ import (
1111 "os"
1212)
1313
14+ // logFormat is the log format from AWS_LAMBDA_LOG_FORMAT (TEXT or JSON)
15+ var logFormat = os .Getenv ("AWS_LAMBDA_LOG_FORMAT" )
16+
17+ // logLevel is the log level from AWS_LAMBDA_LOG_LEVEL
18+ var logLevel = os .Getenv ("AWS_LAMBDA_LOG_LEVEL" )
19+
1420// field represents a Lambda context field to include in log records.
1521type field struct {
1622 key string
@@ -58,7 +64,7 @@ func NewLogHandler(opts ...LogOption) slog.Handler {
5864 }
5965
6066 var h slog.Handler
61- if LogFormat == "JSON" {
67+ if logFormat == "JSON" {
6268 h = slog .NewJSONHandler (os .Stdout , handlerOpts )
6369 } else {
6470 h = slog .NewTextHandler (os .Stdout , handlerOpts )
@@ -130,7 +136,7 @@ func (h *lambdaHandler) WithGroup(name string) slog.Handler {
130136}
131137
132138func parseLogLevel () slog.Level {
133- switch LogLevel {
139+ switch logLevel {
134140 case "DEBUG" :
135141 return slog .LevelDebug
136142 case "INFO" :
Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ func TestParseLogLevel(t *testing.T) {
8181
8282 for _ , tt := range tests {
8383 t .Run (tt .name , func (t * testing.T ) {
84- LogLevel = tt .input
84+ logLevel = tt .input
8585 result := parseLogLevel ()
8686 assert .Equal (t , tt .expected , result )
8787 })
@@ -386,17 +386,11 @@ func TestWithTenantID(t *testing.T) {
386386}
387387
388388func TestNewLogger (t * testing.T ) {
389- LogFormat = "JSON"
390- LogLevel = "INFO"
391-
392389 logger := NewLogger ()
393390 assert .NotNil (t , logger )
394391}
395392
396393func TestNewLogHandler (t * testing.T ) {
397- LogFormat = "JSON"
398- LogLevel = "INFO"
399-
400394 handler := NewLogHandler ()
401395 assert .NotNil (t , handler )
402396
You can’t perform that action at this time.
0 commit comments