0

I'm using Symony 3.3 and Monolog as application logger. All services are using the injected logger. For example:

public function __construct(LoggerInterface $logger)
{
    $this->logger = $logger;
}

public function work() {
    $this->logger->info("Some info");
    $this->logger->debug("Some debug");
}

It happens that I use these services from both controllers and Symfony commands. What I'd like is to handle the logs differently if they are executed from commands.

For example: I have some commands whose purpose is to process a record and the business requires that I store the processing history (logs) in the database for each job.

For example, the command

(server)$ bin/console process:record 12345

should save the log content into record's table, inside "processing_logs" field.

The question is: how to I buffer and extract the list of logs? Ideally, without changing the services and without changing the controllers.

lordrhodos
  • 2,689
  • 1
  • 24
  • 37
user3429660
  • 2,420
  • 4
  • 25
  • 41
  • what is your question? Do you need to read you log files(and find specific ones)? – Petro Popelyshko Jul 01 '17 at 21:09
  • At the end of the command, I'd like to retrieve a list of all the logs that were produced by the services and manually save them into the database. It is inefficient to parse the log files. I was thinking to use BufferHandler, but I have no idea how and I see no examples anywhere. – user3429660 Jul 01 '17 at 21:28
  • Look at this first - [Log to databases(monolog)](https://github.com/Seldaek/monolog/blob/master/doc/02-handlers-formatters-processors.md#log-to-databases) – Petro Popelyshko Jul 02 '17 at 05:41
  • you may need to create custom handlers and use it along with Buffer wrapper – Petro Popelyshko Jul 02 '17 at 06:19

0 Answers0