mirror of
https://github.com/Seldaek/monolog.git
synced 2026-04-26 16:15:49 +03:00
[GH-ISSUE #1931] Curl error when leaving webhookurl empty #831
Labels
No labels
Bug
Documentation
Feature
Needs Work
Support
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/monolog#831
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Jalliuz on GitHub (Dec 20, 2024).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1931
We have a Monolog/Slack "webhook" implementation in our project. It works fine except when you don't have a webhook url
In my local environment I don't immediately have a Slack webhookurl. These are managed by Slack admins of our company so I can't just create one myself.
But the project requires one in the monolog config.
If I leave it empty, my whole project crashes with a curl error in Handler/SlackWebhookHandler.php line 110
Is there an option to disable it?
What I currently did is setting the level
level: emergencyThis is the highest level and I guess it currently never gets thrown.
Solution:
A solution for this bundle can be that if the webhookurl is left empty, no curl will get called
Another solution is adding an option
enabled: falseSo te developer can decide if its enabled in his environment or not
@davidheunis commented on GitHub (Dec 20, 2024):
To address your issue, you're correct that the root cause of the crash stems from the fact that the webhook_url is required by the SlackWebhookHandler in Monolog. If it's left empty or not properly configured in your environment, the handler attempts to send a request, leading to a curl error. There are a few potential solutions to make this more flexible and avoid crashes in environments where a valid Slack webhook URL is not available.
Posible Solution:
Use Environment Variable Default Value. If the environment variable is not set or left empty, you could set a default value to prevent Monolog from trying to send data. You could modify the webhook_url in the Monolog configuration file to check if the environment variable exists and fallback to a default empty value or null.
@Seldaek commented on GitHub (Mar 16, 2025):
Sorry but I don't really think this is a use case that is broad enough to justify adding here. You could extend the class and override
write()to just return early likeif ($this->getWebhookUrl() === '') { return; } parent::write($record);for example.Adding an enabled flag makes no sense to me to just add it for slack, and I don't really want to add this all over the place, the way to not enable something is to not configure it in theory.
And silently not sending if the webhook url is empty sets a bad precedent too that misconfigured handlers will just silently appear to work but won't actually log anything. Currently we have the exact opposite approach whereas misconfigurations fail loudly to ensure that logging works.