[GH-ISSUE #812] Throw exception in StreamHandler upon constructing, not writing #312

Closed
opened 2026-03-04 02:14:02 +03:00 by kerem · 2 comments
Owner

Originally created by @sander-bol on GitHub (Jun 29, 2016).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/812

Currently when using the StreamHandler with a non-writable file location, the exception indicating this is only thrown during the write() operation. During object construction the writability of the stream could already be verified, which would help in making logging a non-breaking aspect of the application. Making this a non-breaking issue currently requires us to wrap all writes in a Try-block.

Originally created by @sander-bol on GitHub (Jun 29, 2016). Original GitHub issue: https://github.com/Seldaek/monolog/issues/812 Currently when using the StreamHandler with a non-writable file location, the exception indicating this is only thrown during the write() operation. During object construction the writability of the stream could already be verified, which would help in making logging a non-breaking aspect of the application. Making this a non-breaking issue currently requires us to wrap all writes in a Try-block.
kerem closed this issue 2026-03-04 02:14:02 +03:00
Author
Owner

@Seldaek commented on GitHub (Jul 2, 2016):

The problem then is that we always open the stream even though in most cases the request won't need to if you only log errors. I'd rather not change that, but you could pass in a resource instead of a stream url by doing the fopen() yourself and that way you catch the failure at instantiation time.

<!-- gh-comment-id:230102226 --> @Seldaek commented on GitHub (Jul 2, 2016): The problem then is that we always open the stream even though in most cases the request won't need to if you only log errors. I'd rather not change that, but you could pass in a resource instead of a stream url by doing the fopen() yourself and that way you catch the failure at instantiation time.
Author
Owner

@Seldaek commented on GitHub (Jul 2, 2016):

Also alternatively note that you can use https://github.com/Seldaek/monolog/blob/master/src/Monolog/Handler/WhatFailureGroupHandler.php to wrap all your handlers if you want to make sure logging never throws.

<!-- gh-comment-id:230102262 --> @Seldaek commented on GitHub (Jul 2, 2016): Also alternatively note that you can use https://github.com/Seldaek/monolog/blob/master/src/Monolog/Handler/WhatFailureGroupHandler.php to wrap all your handlers if you want to make sure logging never throws.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#312
No description provided.