monolog-bundle icon indicating copy to clipboard operation
monolog-bundle copied to clipboard

Using a custom handler with a nested handler

Open gturri opened this issue 10 months ago • 0 comments

Hi,

first of all, thanks for this great piece of software!

I'm trying to define a custom handler which should do some filtering on the LogRecord and then forward some of those to a nested handler. I've spent a couple hours on it, and I'm not sure if I'm missing something or if it's not possible yet.

In some more details: I've seen the issue #206 which is similar to what I'm trying to achieve, and I subsequently see that I can put

type: service
id: my_handler

in order to reference my class.

But I don't understand if (and how) I can reference a nested handler.

Said differently, what I would like to have is a conf similar to the crossed_finger one; ie, like

monolog:
  handlers:
    my_handler:
      type: service
      id: my_handler
      handler: file
    file:
      type: rotating_file

When I read the code of buildHandler I have the feeling that it is not possible. (Unless if it has something to do with the nested config (I'm afraid I don't really understand what that does)).

So my questions are:

  1. Am I missing something; Is the feature I'm looking for already available?
  2. Or, if it is not possible, would you be open to adding it? (in which case I could try to propose a pull request if we can agree on an approach. I guess I should copy what is done for the finger_crossed handler, but I'm afraid there may not be a generic way to inject some nested handler)

gturri avatar Apr 22 '24 21:04 gturri