Closed sunnygoel87 closed 1 year ago
Any update on this ?
Apologies @sunnygoel87, we're reviewing your issue and will update soon.
Hi @sunnygoel87,
Thanks for raising this issue. The "POWERTOOLS_LOG_LEVEL" configuration specifies the minimum log level you desire to log. The methods such as LogTrace
, LogDebug
, LogInformation
etc. are the ones actually specify the level of the logs.
LambdaPowertools ignores a log when the log level below the specified "POWERTOOLS_LOG_LEVEL". Here are some information about the Log level.
If you would like to specify the log level at runtime you can do so by using The Log
method. The Log method's first parameter, LogLevel, indicates the severity of the log.
logger.Log(LogLevel.Information, "Welcome to AWS Lambda Powertools for .NET");
@amirkaws - Thanks for your response and sharing the additional information about Log Level.
Can I say that If a log level is not specified explicitly (as shown in below mentioned statement), then by default Lambda Powertools logs the message with "information" Log severity.
logger.Log("Welcome to AWS Lambda Powertools for .NET");
And if in case "POWERTOOLS_LOG_LEVEL" environment variable is set to "error", then we will not even see anything in CloudWatch Log Group. Because "information" log level is below the "error" log level, correct ?
Hi @sunnygoel87,
No problem. no currently you need to pass the required log level or use one of the ILogger Extensions methods. However. However, I'll have a chat with other maintainer to see if we can add that method as well.
Close this ticket as decided to stay with ILogger Extensions methods which requires to pass the log level.
Expected Behaviour
Log events in CloudWatch with
debug
log level.Current Behaviour
Log events are showing
info
log level despite setting the following environment variable in the Lambda fn.POWERTOOLS_LOG_LEVEL: debug
Code snippet
Here is the code snippet from Function.cs file.
Steps to Reproduce
1.) Create an empty .NET 6 based lambda function using the templates provided by Amazon.Lambda.Templates NuGet package. 2.) Use the code shared above in Function.cs file. 2.) Add the following nuget package - AWS.Lambda.Powertools.Logging 3.) Deploy and invoke the function a few times. 4.) You will notice the Log events with Log level "Info" 5.) Now, add the following environment variables in the Lambda fn. either manually using AWS console or AWS CLI command.
POWERTOOLS_LOG_LEVEL: debug
POWERTOOLS_SERVICE_NAME: <give any meaningful name>
6.) Invoke the function again a few times. You will again see the log events being logged with "Info" log level.
AWS Lambda Powertools for .NET version
latest
AWS Lambda function runtime
dotnet6