Bonjour,
Dans un script d'import (une commande héritant de ContainerAwareCommand) je cherche comment loguer les événements et les afficher dans la console.
Mon script vas effectuer différentes tâches et un import par 'Client'
Je voudrais que chaque client soit informé si il y a un problème dans son import avec les détails des erreurs.
et à la fin je veux un rapport complet pour moi.
Je me retrouve donc avec deux logger.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 class ImportCommand extends ContainerAwareCommand { private function __execute(InputInterface $input, OutputInterface $output) { $log_file_path = 'logs/global_import.log'; $logger = new \Symfony\Bridge\Monolog\Logger('global'); $logger->pushHandler(new StreamHandler($log_file_path, Logger::DEBUG)); $logger->pushHandler(new ConsoleHandler($output, true, array( OutputInterface::VERBOSITY_NORMAL => Logger::INFO, OutputInterface::VERBOSITY_QUIET => Logger::CRITICAL, ))); // do something for all client $logger->info('Un truc réussit'); foreach ($this->em->getRepository('Lb2gSiteBundle:Client')->findAll() as $client) { $log_file_client_path = 'logs/import_client_'.$client->getId().'log'; $logger_client = new \Symfony\Bridge\Monolog\Logger('client_'.$client->getId()); $logger_client->pushHandler(new StreamHandler($log_file_client_path, Logger::DEBUG)); // do something for one client $logger_client->info('Salut ' . $client->getNom()); $logger->info('Salut ' . $client->getNom()); if (rand (0,1)) { $logger_client->error("Pas de bol !"); $logger->error("Pas de bol !"); } // If error for the client notify him by mail if ($logger_client->countErrors()) { mail($client->getEmail(), 'error', file_get_contents($log_file_client_path)); } } // if errors if ($logger->countErrors()) { mail('moi@ici.la', 'error', file_get_contents($log_file_path)); } } }
$logger_client et $logger.
Mais lors que je veux logguer un truc dans les deux je suis obliger de faire deux appels.
Exist-il un moyen de dire au $logger_client que tout ce qui lui est dit doit être aussi transmis à $logger ?
Partager