[PR #720] [MERGED] Created "ProcessHandler", that logs records to the STDIN of a process. #1314

Closed
opened 2026-03-04 03:09:22 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Seldaek/monolog/pull/720
Author: @ArSn
Created: 1/15/2016
Status: Merged
Merged: 5/26/2016
Merged by: @Seldaek

Base: masterHead: master


📝 Commits (3)

  • 1be08de Created "ProcessHandler", that logs records to the STDIN of a custom process, defined by given command.
  • f13011e Removed obsolete var_export(). Made construction argument validation tests simpler and more readable.
  • fbe0bae Replaced indention tabs with 4 spaces in ProcessHandler and its test.

📊 Changes

3 files changed (+418 additions, -0 deletions)

View changed files

📝 doc/02-handlers-formatters-processors.md (+1 -0)
src/Monolog/Handler/ProcessHandler.php (+222 -0)
tests/Monolog/Handler/ProcessHandlerTest.php (+195 -0)

📄 Description

This implements #452, I hope you find it useful.

Some points/questions that I'd like to add here:

  1. I did intentionally not include an option to pass the already opened process to the handler for now, but rather require the consumer to pass a command. This is due to the circumstance that the proc_open() call has to be quite specific in order for the handler to work properly.
  2. I am not entirely sure about the name. Although it was suggested in the linked issue, it might be true that "ProcessHandler" could cause some confusion, as there are classes like "ProcessableHandlerInterface" and "ProcessableHandlerTrait" in the codebase, which are unrelated. I could not think of anything better and therefore went with it for now, but please, suggestions are welcome!
  3. Is there any documentation that I should update, like "How to use this handler" or such?

Apart from that, I have a few ideas of how to extend this handler, but was not sure about the demand or use cases for that, and hence, left them out for now:

  1. There could be something like a "strategy" (probably also implementing the Strategy Pattern), in how the process is handled, e.g.: Open new process on every write; OR keep process open (like it does now); OR use a time based transient handling
  2. There could be even more options in the constructor, as proc_open() also:
    1. allows an $env parameter to pass environment variables to the process
    2. allows an $other_options parameter, that seems to be only doing anything on windows right now (I don't see very much use in implementing this one)
  3. The proc_close() function actually returns the termination status of the handled process. This could be returned from ProcessHandler::close(), as it may be helpful for some.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Seldaek/monolog/pull/720 **Author:** [@ArSn](https://github.com/ArSn) **Created:** 1/15/2016 **Status:** ✅ Merged **Merged:** 5/26/2016 **Merged by:** [@Seldaek](https://github.com/Seldaek) **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (3) - [`1be08de`](https://github.com/Seldaek/monolog/commit/1be08de729b944b2e3bc116079f519ff8f9fe660) Created "ProcessHandler", that logs records to the STDIN of a custom process, defined by given command. - [`f13011e`](https://github.com/Seldaek/monolog/commit/f13011e03ef0c9672c86f7169d11c903fd666276) Removed obsolete var_export(). Made construction argument validation tests simpler and more readable. - [`fbe0bae`](https://github.com/Seldaek/monolog/commit/fbe0bae8c9e469cbcd4ac9f51e72b9bcc6174936) Replaced indention tabs with 4 spaces in ProcessHandler and its test. ### 📊 Changes **3 files changed** (+418 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `doc/02-handlers-formatters-processors.md` (+1 -0) ➕ `src/Monolog/Handler/ProcessHandler.php` (+222 -0) ➕ `tests/Monolog/Handler/ProcessHandlerTest.php` (+195 -0) </details> ### 📄 Description This implements #452, I hope you find it useful. **Some points/questions that I'd like to add here:** 1. I did intentionally not include an option to pass the already opened process to the handler for now, but rather require the consumer to pass a command. This is due to the circumstance that the `proc_open()` call has to be quite specific in order for the handler to work properly. 2. I am not entirely sure about the name. Although it was suggested in the linked issue, it might be true that "ProcessHandler" could cause some confusion, as there are classes like "ProcessableHandlerInterface" and "ProcessableHandlerTrait" in the codebase, which are unrelated. I could not think of anything better and therefore went with it for now, but please, suggestions are welcome! 3. Is there any documentation that I should update, like "How to use this handler" or such? **Apart from that, I have a few ideas of how to extend this handler, but was not sure about the demand or use cases for that, and hence, left them out for now:** 1. There could be something like a "strategy" (probably also implementing the Strategy Pattern), in how the process is handled, e.g.: Open new process on every write; OR keep process open (like it does now); OR use a time based transient handling 2. There could be even more options in the constructor, as [`proc_open()`](http://php.net/proc_open) also: 1. allows an `$env` parameter to pass environment variables to the process 2. allows an `$other_options` parameter, that seems to be only doing anything on windows right now (I don't see very much use in implementing this one) 3. The [`proc_close()`](http://php.net/proc_close) function actually returns the termination status of the handled process. This could be returned from `ProcessHandler::close()`, as it _may_ be helpful for some. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-04 03:09:22 +03:00
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#1314
No description provided.