@@ -133,6 +133,13 @@ class Logger extends Utility implements LoggerInterface {
133
133
* Log level used internally by the current instance of Logger.
134
134
*/
135
135
private logLevel : number = LogLevelThreshold . INFO ;
136
+
137
+ /**
138
+ * Advanced Logging Control Log Level
139
+ * If not a valid value this will be left undefined, even if the
140
+ * environment variable AWS_LAMBDA_LOG_LEVEL is set
141
+ */
142
+ #alcLogLevel?: Uppercase < LogLevel > ;
136
143
/**
137
144
* Persistent log attributes that will be logged in all log items.
138
145
*/
@@ -819,16 +826,15 @@ class Logger extends Utility implements LoggerInterface {
819
826
}
820
827
821
828
private awsLogLevelShortCircuit ( selectedLogLevel ?: string ) : boolean {
822
- const awsLogLevel = this . getEnvVarsService ( ) . getAwsLogLevel ( ) ;
823
- if ( this . isValidLogLevel ( awsLogLevel ) ) {
824
- this . logLevel = LogLevelThreshold [ awsLogLevel ] ;
829
+ if ( this . #alcLogLevel !== undefined ) {
830
+ this . logLevel = LogLevelThreshold [ this . #alcLogLevel] ;
825
831
826
832
if (
827
833
this . isValidLogLevel ( selectedLogLevel ) &&
828
834
this . logLevel > LogLevelThreshold [ selectedLogLevel ]
829
835
) {
830
836
this . #warnOnce(
831
- `Current log level (${ selectedLogLevel } ) does not match AWS Lambda Advanced Logging Controls minimum log level (${ awsLogLevel } ). This can lead to data loss, consider adjusting them.`
837
+ `Current log level (${ selectedLogLevel } ) does not match AWS Lambda Advanced Logging Controls minimum log level (${ this . #alcLogLevel } ). This can lead to data loss, consider adjusting them.`
832
838
) ;
833
839
}
834
840
@@ -1306,6 +1312,11 @@ class Logger extends Utility implements LoggerInterface {
1306
1312
) ;
1307
1313
1308
1314
// configurations that affect Logger behavior
1315
+ const AlcLogLevel = this . getEnvVarsService ( ) . getAwsLogLevel ( ) ;
1316
+ if ( this . isValidLogLevel ( AlcLogLevel ) ) {
1317
+ this . #alcLogLevel = AlcLogLevel ;
1318
+ }
1319
+
1309
1320
this . setLogEvent ( ) ;
1310
1321
this . setInitialLogLevel ( logLevel ) ;
1311
1322
this . setInitialSampleRate ( sampleRateValue ) ;
@@ -1378,10 +1389,12 @@ class Logger extends Utility implements LoggerInterface {
1378
1389
this . #bufferConfig. bufferAtVerbosity =
1379
1390
LogLevelThreshold [ bufferAtLogLevel ] ;
1380
1391
}
1381
- const AlcLogLevel =
1382
- this . getEnvVarsService ( ) . getAwsLogLevel ( ) as keyof typeof LogLevelThreshold ;
1383
1392
1384
- if ( LogLevelThreshold [ AlcLogLevel ] > this . #bufferConfig. bufferAtVerbosity ) {
1393
+ if (
1394
+ this . #alcLogLevel !== undefined &&
1395
+ LogLevelThreshold [ this . #alcLogLevel] >
1396
+ this . #bufferConfig. bufferAtVerbosity
1397
+ ) {
1385
1398
this . #warnOnce(
1386
1399
'Advanced Loggging Controls (ALC) Log Level is less verbose than Log Buffering Log Level. Buffered logs will be filtered by ALC'
1387
1400
) ;
@@ -1451,10 +1464,12 @@ class Logger extends Utility implements LoggerInterface {
1451
1464
)
1452
1465
) ;
1453
1466
}
1454
- const AlcLogLevel =
1455
- this . getEnvVarsService ( ) . getAwsLogLevel ( ) as keyof typeof LogLevelThreshold ;
1456
1467
1457
- if ( LogLevelThreshold [ AlcLogLevel ] > this . #bufferConfig. bufferAtVerbosity ) {
1468
+ if (
1469
+ this . #alcLogLevel !== undefined &&
1470
+ LogLevelThreshold [ this . #alcLogLevel] >
1471
+ this . #bufferConfig. bufferAtVerbosity
1472
+ ) {
1458
1473
this . #warnOnce(
1459
1474
'Advanced Loggging Controls (ALC) Log Level is less verbose than Log Buffering Log Level. Some logs might be missing.'
1460
1475
) ;
0 commit comments