Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit feea841

Browse files
committedApr 16, 2025·
Store Advanced Logging Control level in Logger
1 parent c2a0e98 commit feea841

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed
 

‎packages/logger/src/Logger.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ class Logger extends Utility implements LoggerInterface {
133133
* Log level used internally by the current instance of Logger.
134134
*/
135135
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>;
136143
/**
137144
* Persistent log attributes that will be logged in all log items.
138145
*/
@@ -819,16 +826,15 @@ class Logger extends Utility implements LoggerInterface {
819826
}
820827

821828
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];
825831

826832
if (
827833
this.isValidLogLevel(selectedLogLevel) &&
828834
this.logLevel > LogLevelThreshold[selectedLogLevel]
829835
) {
830836
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.`
832838
);
833839
}
834840

@@ -1306,6 +1312,11 @@ class Logger extends Utility implements LoggerInterface {
13061312
);
13071313

13081314
// configurations that affect Logger behavior
1315+
const AlcLogLevel = this.getEnvVarsService().getAwsLogLevel();
1316+
if (this.isValidLogLevel(AlcLogLevel)) {
1317+
this.#alcLogLevel = AlcLogLevel;
1318+
}
1319+
13091320
this.setLogEvent();
13101321
this.setInitialLogLevel(logLevel);
13111322
this.setInitialSampleRate(sampleRateValue);
@@ -1378,10 +1389,12 @@ class Logger extends Utility implements LoggerInterface {
13781389
this.#bufferConfig.bufferAtVerbosity =
13791390
LogLevelThreshold[bufferAtLogLevel];
13801391
}
1381-
const AlcLogLevel =
1382-
this.getEnvVarsService().getAwsLogLevel() as keyof typeof LogLevelThreshold;
13831392

1384-
if (LogLevelThreshold[AlcLogLevel] > this.#bufferConfig.bufferAtVerbosity) {
1393+
if (
1394+
this.#alcLogLevel !== undefined &&
1395+
LogLevelThreshold[this.#alcLogLevel] >
1396+
this.#bufferConfig.bufferAtVerbosity
1397+
) {
13851398
this.#warnOnce(
13861399
'Advanced Loggging Controls (ALC) Log Level is less verbose than Log Buffering Log Level. Buffered logs will be filtered by ALC'
13871400
);
@@ -1451,10 +1464,12 @@ class Logger extends Utility implements LoggerInterface {
14511464
)
14521465
);
14531466
}
1454-
const AlcLogLevel =
1455-
this.getEnvVarsService().getAwsLogLevel() as keyof typeof LogLevelThreshold;
14561467

1457-
if (LogLevelThreshold[AlcLogLevel] > this.#bufferConfig.bufferAtVerbosity) {
1468+
if (
1469+
this.#alcLogLevel !== undefined &&
1470+
LogLevelThreshold[this.#alcLogLevel] >
1471+
this.#bufferConfig.bufferAtVerbosity
1472+
) {
14581473
this.#warnOnce(
14591474
'Advanced Loggging Controls (ALC) Log Level is less verbose than Log Buffering Log Level. Some logs might be missing.'
14601475
);

0 commit comments

Comments
 (0)
Please sign in to comment.