Skip to content
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

Runtime environment variable support for log level #444

Closed
uncaught opened this issue Oct 25, 2022 · 1 comment
Closed

Runtime environment variable support for log level #444

uncaught opened this issue Oct 25, 2022 · 1 comment

Comments

@uncaught
Copy link

uncaught commented Oct 25, 2022

Follow up to #357

It is inconvenient to have environment variables only be applied at container build time. This kind of defeats the purpose of environment variables and makes pre-building the container impossible.

By simply removing levelToMonologConst and using the parameters as they are, everything works beautifully at runtime.

The only thing that won't happen is the thrown \InvalidArgumentException if the level is invalid. But validation of environment variables is never done at compile time in any other situation. And this validation was only introduced by #357, which, in my opinion, should not have been accepted.

To avoid a BC-break due to the validation, I'd like to see an option to disable levelToMonologConst. I've checked all monolog handlers that use the level coming from levelToMonologConst and all of them use Monolog\Logger::toMonologLevel to cast the level. There is no need to cast the level in this extension at build time. You might then make that the default behavior in a new major version and drop it eventually.

Would you be open to this change? What arguments are there for still having levelToMonologConst?

Is that validation even a BC-break if it was simply removed? It's not like a missing config validation will make anything stop working.

@GromNaN
Copy link
Member

GromNaN commented Dec 2, 2022

I have the same issue and made a PR that converts the value at runtime #446. I think there is no need for a breaking change nor a new option.

GromNaN added a commit that referenced this issue Dec 5, 2022
This PR was merged into the 3.x-dev branch.

Discussion
----------

Resolve "level" env var at runtime

Resolves #413, #444

Currently, the log level is read when the container built. This means we cannot change a log level at runtime using env vars.

With this change, log level can be modified for a specific command run: `LOG_LEVEL=debug bin/console ...`

~I would like to get some feedbacks before updating tests. I don't know yet what is the best strategy to check the resolution of the values.~

Commits
-------

db45663 Resolve levels at runtime using Monolog's native behavior.
@GromNaN GromNaN closed this as completed Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants