-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Log Level SILENT must be set before instantiation #1503
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Hi @zirkelc thank you for taking the time to open the issue. The behavior you describe is intended. You have multiple ways of setting the e log level, both when instantiating the Logger and at runtime. One of them is via environment variables, which together with the If you want to change the log level after that, aka at runtime, then you can do so using the |
Hi @dreamorosi thanks for the quick response! I understand, I thought changing the environment variable In some case I don't have access to the A similar discussion happened a few months ago: #1198 |
I'm not sure I'm following, if you don't have access to the logger then how are you logging? Regarding to that discussion, we decided to support local development via another environment variable called Overall I don't think evaluating the log level every time we need to print a log is a good idea for performance, and generally speaking I don't consider environment variables something that should change at runtime in most cases. I think it'd help if you could share a few more details on the use case and what you're trying to do, maybe I can help find an alternative. |
I meant that the logger instance is created inside functions that are called, but those functions do not export the logger instance itself. Nonetheless, I thought it might be a bug that changing |
|
Expected Behaviour
I expected the log level to be a toggle that is being evaluated at the time a message is being printed. That means if I set
process.env.LOG_LEVEL="SILENT"
, the message should not be printed and if I reset the log level the message should be printed.Current Behaviour
The log level is evaluated at the time of instantiation. That means changing the log level after the logger was created, has no effect and will still print messages.
This prints:
And this doesn't print:
Code snippet
See sandbox: https://codesandbox.io/s/muddy-bush-j54nwp?file=/src/index.ts
Steps to Reproduce
See sandbox: https://codesandbox.io/s/muddy-bush-j54nwp?file=/src/index.ts
Possible Solution
The
process.env.LOG_LEVEL
variable should always be checked when a message is being printed. If theprocess.env.LOG_LEVEL
differs from the constructorlogLevel
, the environment variable should have priority.Alternatively, the if the constructor was was called without
logLevel
, then the log level fromprocess.env.LOG_LEVEL
, should always have priority.Powertools for AWS Lambda (TypeScript) version
1.7
AWS Lambda function runtime
18.x
Packaging format used
npm
Execution logs
No response
The text was updated successfully, but these errors were encountered: