mirror of
https://github.com/Seldaek/monolog.git
synced 2026-04-26 16:15:49 +03:00
[GH-ISSUE #798] Question: how to handle connection errors while logging? #305
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#305
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 @doenietzomoeilijk on GitHub (May 27, 2016).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/798
I'm running into a problem, and I was wondering about the best way to tackle it.
I'm using Monolog to log to several handlers: a custom handler to write certain events to our own database, one to log important errors to Slack, and one that logs everything and the kitchen sink to Redis, to be picked up by an ELK stack. The last one is giving me a bit of grief, since every now and then, it can't connect to the Redis instance properly or it bombs out when writing a message. I was wondering what to do with the Exceptions that get thrown because of connection issues - I can and do catch them if they happen when using the initial connect, before I've pushed the Redishandler, but after that it's kinda out of my hands. If anything happens during storage (in our case: at the
rpushstage), an exception gets thrown and bubbles all the way up into my application.So I'm kind of torn here about what to do: my first hunch would be to try-catch pushing to the handlers and returning false if something is caught (so I don't have to change my code in all the places where I log things), but that'd make me lose sight of when logging failed to that handler. Alternatively I could wrap the Redis handler and have it log its problems in a separate logger (which would make the solution tightly bound to my app, and logging from within logging also sounds like something that could backfire at some point).
I was wondering about how other people would handle this issue. Again, the main solution is of course getting Redis to play nice, but at the same time I want to make my logging more robust / fault tolerant. As it stands, a faulty log receiver that is not critical to the application can bring the application down, and that shouldn't be possible IMO.
TL;DR misbehaving log receptacles are causing errors in my application; I'd prefer my application to keep working even if logging doesn't. What do?
@Seldaek commented on GitHub (May 27, 2016):
What do? Use WhatFailureGroupHandler to wrap redis and/or other handlers that you don't want to be able to blow up the app. By default we don't catch exception as it might surface a handler misconfiguration or such.
@doenietzomoeilijk commented on GitHub (May 27, 2016):
That pretty much would be my solution, so thanks for pointing that one out as I had missed it myself. Too bad it's not usable right now, as I'm on PHP <7, but at least it tells my my idea wasn't totally insane. :) Thanks for the input!
@Seldaek commented on GitHub (May 27, 2016):
Oh no it is available in 1.x as well.