0

I need to add some action, when application runs one of Monolog\Logger methods (info, error, warning etc.) and do some custom code.

for example:

$this->logger->error('Some error');

should do error output - basic action for Monolog\Logger, but after that send error text via API ...

Alexey Samara
  • 131
  • 1
  • 13

1 Answers1

1

Please read the Symfony Monolog documentation and check out if you find any network or server handler from the list of included handlers and their configuration options.

If there is no suitable handler you should create a custom handler class using the service handler type, e.g. src/AppBundle/Monolog/YourApiHandler.php which needs to implement at least the HandlerInterface , but you could also see if another class you could inherit from is more appropriate for your task, e.g. AbstractProcesssingHandler .

Once you have implemented your handler just define a service for it

# app/config/services.yml
services:
    my_handler:
        class: AppBundle\Monolog\YourApiHandler

and add it to the monolog configuration:

# app/config/config.yml
monolog:
    handlers:
        my_handler:
            type: service
            id: my_handler
lordrhodos
  • 2,689
  • 1
  • 24
  • 37