From 30faaa7b088563c4551591ed0b06d74dd2331675 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Mon, 9 Jan 2017 04:21:31 +0300 Subject: [PATCH] Monolog log rotation in dev environment. Console command logging updated. --- app/config/config_dev.yml | 2 + .../Command/UpdateSubscriptionsCommand.php | 72 ++++++++++++------- 2 files changed, 50 insertions(+), 24 deletions(-) diff --git a/app/config/config_dev.yml b/app/config/config_dev.yml index 937b077..08f10cb 100644 --- a/app/config/config_dev.yml +++ b/app/config/config_dev.yml @@ -21,6 +21,8 @@ monolog: channels: [!event] console: type: console + verbosity_levels: + VERBOSITY_NORMAL: INFO channels: [!event, !doctrine] # uncomment to get logging in your browser # you may have to allow bigger header sizes in your Web server configuration diff --git a/src/Skobkin/Bundle/PointToolsBundle/Command/UpdateSubscriptionsCommand.php b/src/Skobkin/Bundle/PointToolsBundle/Command/UpdateSubscriptionsCommand.php index 95697f0..9733cac 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Command/UpdateSubscriptionsCommand.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Command/UpdateSubscriptionsCommand.php @@ -46,7 +46,7 @@ class UpdateSubscriptionsCommand extends ContainerAwareCommand $em = $this->getContainer()->get('doctrine.orm.entity_manager'); $userRepository = $em->getRepository('SkobkinPointToolsBundle:User'); - $log->info('UpdateSubscriptionsCommand started.'); + $log->debug('UpdateSubscriptionsCommand started.'); /** @var UserApi $api */ $api = $this->getContainer()->get('app.point.api_user'); @@ -75,15 +75,21 @@ class UpdateSubscriptionsCommand extends ContainerAwareCommand return 1; } - if (OutputInterface::VERBOSITY_VERBOSE === $output->getVerbosity()) { - $output->writeln('Getting service subscribers'); - } + $log->info('Getting service subscribers'); try { $usersForUpdate = $api->getUserSubscribersById($serviceUserId); } catch (\Exception $e) { - $output->writeln('Error while getting service subscribers'); - $log->error('Error while getting service subscribers.', ['user_login' => $serviceUser->getLogin(), 'user_id' => $serviceUser->getId(), 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()]); + $log->warning( + 'Error while getting service subscribers. Fallback to local list.', + [ + 'user_login' => $serviceUser->getLogin(), + 'user_id' => $serviceUser->getId(), + 'message' => $e->getMessage(), + 'file' => $e->getFile(), + 'line' => $e->getLine() + ] + ); $usersForUpdate = []; @@ -91,56 +97,72 @@ class UpdateSubscriptionsCommand extends ContainerAwareCommand $usersForUpdate[] = $subscription->getSubscriber(); } - $output->writeln('Fallback to local list'); - $log->error('Fallback to local list'); - if (!count($usersForUpdate)) { $log->info('No local subscribers. Finishing.'); return 0; } } - if (OutputInterface::VERBOSITY_VERBOSE === $output->getVerbosity()) { - $output->writeln('Updating service subscribers'); - } + $log->debug('Updating service subscribers'); // Updating service subscribers try { $subscriptionsManager->updateUserSubscribers($serviceUser, $usersForUpdate); } catch (\Exception $e) { - $log->error('Error while updating service subscribers', ['user_login' => $serviceUser->getLogin(), 'user_id' => $serviceUser->getId(), 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()]); + $log->error( + 'Error while updating service subscribers', + [ + 'user_login' => $serviceUser->getLogin(), + 'user_id' => $serviceUser->getId(), + 'message' => $e->getMessage(), + 'file' => $e->getFile(), + 'line' => $e->getLine() + ] + ); return 1; } } - if (OutputInterface::VERBOSITY_VERBOSE === $output->getVerbosity()) { - $output->writeln('Processing users subscribers'); - } + $log->info('Processing users subscribers'); // Updating users subscribers foreach ($usersForUpdate as $user) { - $output->writeln(' Processing @' . $user->getLogin()); - $log->info('Processing @' . $user->getLogin()); + $log->info('Processing @'.$user->getLogin()); try { $userCurrentSubscribers = $api->getUserSubscribersById($user->getId()); } catch (\Exception $e) { - $output->writeln(' Error while getting subscribers. Skipping.'); - $log->error('Error while getting subscribers.', ['user_login' => $user->getLogin(), 'user_id' => $user->getId(), 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()]); + $log->error( + 'Error while getting subscribers. Skipping.', + [ + 'user_login' => $user->getLogin(), + 'user_id' => $user->getId(), + 'message' => $e->getMessage(), + 'file' => $e->getFile(), + 'line' => $e->getLine() + ] + ); continue; } - if (OutputInterface::VERBOSITY_VERBOSE === $output->getVerbosity()) { - $output->writeln(' Updating user subscribers'); - } + $log->debug('Updating user subscribers'); try { // Updating user subscribers $subscriptionsManager->updateUserSubscribers($user, $userCurrentSubscribers); } catch (\Exception $e) { - $log->error('Error while updating user subscribers', ['user_login' => $user->getLogin(), 'user_id' => $user->getId(), 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()]); + $log->error( + 'Error while updating user subscribers', + [ + 'user_login' => $user->getLogin(), + 'user_id' => $user->getId(), + 'message' => $e->getMessage(), + 'file' => $e->getFile(), + 'line' => $e->getLine() + ] + ); } // @todo move to the config @@ -151,6 +173,8 @@ class UpdateSubscriptionsCommand extends ContainerAwareCommand $em->flush(); $em->commit(); + $log->debug('Finished'); + return 0; } } \ No newline at end of file