Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@raphaelportmann
Copy link

@raphaelportmann raphaelportmann commented Dec 11, 2025

I tried to implement a generic webhook handler using HTTP(S) POST requests with a JSON payload.
I have seen an old discussion regarding the implementation of generic handlers and using third-party packages for more specific handlers, but believe this handler would be a good addition to the monolog core package.

  • As mentioned here there are many plattforms like zapier and n8n (or building something yourself) that provide webhook endpoints to accept data in pretty much any format. Instead of creating more and more handlers for each of these plattforms or requiring third-party packages, this handler could be used for most of these plattforms.
  • The handler currently extends the SocketHandler (adapted from the FleepHookHandler integration). Is this still the preferred way instead uf using curl?
  • The only handler that would provide similar functionality would be the PSR-18 HTTP client integration, but requires another package and looks like maintenance lags behind.
  • Didn't have the time to look into more features, like supporting secrets or other forms of authentication, but in that case it would probably be better to use PSR-18 clients directly. Is there a reason why this is a separate package but very specific integrations are part of the core?

My specific use-case would be to easily send logs to external webhooks - in my case inside a Laravel application, which allows for simple monolog configuration: e.g. https://github.com/laravel/laravel/blob/12.x/config/logging.php#L85
With this handler it could look like this:

'webhook' => [
    'driver' => 'monolog',
    'level' => env('LOG_LEVEL', 'warning'),
    'handler' => env('LOG_WEBHOOK_HANDLER', WebhookHandler::class),
    'handler_with' => [
        'url' => env('LOG_WEBHOOK_URL'),
    ],
],
// LOG_WEBHOOK_URL="https://example.com/webhook/abc123"

Just wanted to make a proposal. If you recommend another approach, let me know.

@stof
Copy link
Contributor

stof commented Dec 11, 2025

Doing HTTP by hand over a raw socket looks bad to me (even though some handlers already do it). The implementation does not implement the full HTTP specification, which might create issues depending on how the server answers.
Using an actual HTTP client to perform an HTTP request will be a lot more reliable (and might use HTTP/2 or HTTP/3 btw, instead of using HTTP/1).

To me, it should at least use ext-curl (as done in some existing handlers)

  • Is there a reason why this is a separate package but very specific integrations are part of the core?

The rule to reject very specific integrations from the core (in favor of having them maintained in third-party packages by people interested in them and using the dependencies they need) was not in place in the first years of existence of Monolog.

@raphaelportmann
Copy link
Author

raphaelportmann commented Dec 11, 2025

Alright, but before investing more time - do you think this handler is something that could be merged into the core as there are no generic HTTP handlers?
Will definitely look into migrating to curl. If you have other feedback for improvement also let me know.
Do you think integrating PSR-18 HTTP Clients would be out-of-scope? Could also look into getting monolog-http up to date, but looks like the repo is not maintained actively.

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

Successfully merging this pull request may close these issues.

2 participants