Seldaek / monolog

Sends your logs to files, sockets, inboxes, databases and various web services
https://seldaek.github.io/monolog/
MIT License
21.02k stars 1.9k forks source link

Processors should implement a ProcessorInterface #486

Closed ahmadnazir closed 9 years ago

ahmadnazir commented 9 years ago

Hi,

I was wondering what is that reason to rely on the magic __invoke method inside the processors. I would expect that the processors should implement a ProcessorInterface with at least the following methods:

public function process(array $record);
public function setData(array $data); // Data that will be added to the record
public function setKey($key); // If we want to add data to key other than 'extra'

What are your thoughts? If it makes sense, I am interested in working on it and sending a pull request.

Seldaek commented 9 years ago

The reason to use __invoke is that the processor "interface" is just a any callable. It makes it possible to use anonymous functions as minimalistic processors for example. There is no need for more than that so I don't see the benefit of introducing an actual interface.

zored commented 6 years ago

@Seldaek however sometimes interfaces can be useful in OOP-based projects.

For example, in Symfony it's required to put monolog.processor tag on processor services. But if there was ProcessorInterface, I could map it on tag and avoid explicit tags.