Replace log topics strings by constants

[MAILPOET-2444]
This commit is contained in:
Rostislav Wolny
2019-10-08 11:39:27 +02:00
committed by Jack Kitterhing
parent d3345d35d0
commit 73bc62227a
8 changed files with 24 additions and 21 deletions

View File

@ -83,14 +83,14 @@ class Scheduler {
} }
function processPostNotificationNewsletter($newsletter, $queue) { function processPostNotificationNewsletter($newsletter, $queue) {
$this->logger_factory->getLogger('post-notifications')->addInfo( $this->logger_factory->getLogger(LoggerFactory::TOPIC_POST_NOTIFICATIONS)->addInfo(
'process post notification in scheduler', 'process post notification in scheduler',
['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id] ['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id]
); );
// ensure that segments exist // ensure that segments exist
$segments = $newsletter->segments()->findMany(); $segments = $newsletter->segments()->findMany();
if (empty($segments)) { if (empty($segments)) {
$this->logger_factory->getLogger('post-notifications')->addInfo( $this->logger_factory->getLogger(LoggerFactory::TOPIC_POST_NOTIFICATIONS)->addInfo(
'post notification no segments', 'post notification no segments',
['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id] ['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id]
); );
@ -102,7 +102,7 @@ class Scheduler {
$subscribers_count = $this->subscribers_finder->addSubscribersToTaskFromSegments($queue->task(), $segments); $subscribers_count = $this->subscribers_finder->addSubscribersToTaskFromSegments($queue->task(), $segments);
if (empty($subscribers_count)) { if (empty($subscribers_count)) {
$this->logger_factory->getLogger('post-notifications')->addInfo( $this->logger_factory->getLogger(LoggerFactory::TOPIC_POST_NOTIFICATIONS)->addInfo(
'post notification no subscribers', 'post notification no subscribers',
['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id] ['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id]
); );
@ -119,7 +119,7 @@ class Scheduler {
$queue->save(); $queue->save();
// update notification status // update notification status
$notification_history->setStatus(Newsletter::STATUS_SENDING); $notification_history->setStatus(Newsletter::STATUS_SENDING);
$this->logger_factory->getLogger('post-notifications')->addInfo( $this->logger_factory->getLogger(LoggerFactory::TOPIC_POST_NOTIFICATIONS)->addInfo(
'post notification set status to sending', 'post notification set status to sending',
['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id] ['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id]
); );

View File

@ -66,7 +66,7 @@ class SendingQueue {
if (!$queue instanceof SendingTask) continue; if (!$queue instanceof SendingTask) continue;
ScheduledTaskModel::touchAllByIds([$queue->task_id]); ScheduledTaskModel::touchAllByIds([$queue->task_id]);
$this->logger_factory->getLogger('newsletters')->addInfo( $this->logger_factory->getLogger(LoggerFactory::TOPIC_NEWSLETTERS)->addInfo(
'sending queue processing', 'sending queue processing',
['task_id' => $queue->task_id] ['task_id' => $queue->task_id]
); );
@ -77,7 +77,7 @@ class SendingQueue {
// pre-process newsletter (render, replace shortcodes/links, etc.) // pre-process newsletter (render, replace shortcodes/links, etc.)
$newsletter = $this->newsletter_task->preProcessNewsletter($newsletter, $queue); $newsletter = $this->newsletter_task->preProcessNewsletter($newsletter, $queue);
if (!$newsletter) { if (!$newsletter) {
$this->logger_factory->getLogger('newsletters')->addInfo( $this->logger_factory->getLogger(LoggerFactory::TOPIC_NEWSLETTERS)->addInfo(
'delete task in sending queue', 'delete task in sending queue',
['task_id' => $queue->task_id] ['task_id' => $queue->task_id]
); );
@ -98,7 +98,7 @@ class SendingQueue {
// get subscribers // get subscribers
$subscriber_batches = new BatchIterator($queue->task_id, $this->batch_size); $subscriber_batches = new BatchIterator($queue->task_id, $this->batch_size);
foreach ($subscriber_batches as $subscribers_to_process_ids) { foreach ($subscriber_batches as $subscribers_to_process_ids) {
$this->logger_factory->getLogger('newsletters')->addInfo( $this->logger_factory->getLogger(LoggerFactory::TOPIC_NEWSLETTERS)->addInfo(
'subscriber batch processing', 'subscriber batch processing',
['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id, 'subscriber_batch_count' => count($subscribers_to_process_ids)] ['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id, 'subscriber_batch_count' => count($subscribers_to_process_ids)]
); );
@ -129,7 +129,7 @@ class SendingQueue {
continue; continue;
} }
} }
$this->logger_factory->getLogger('newsletters')->addInfo( $this->logger_factory->getLogger(LoggerFactory::TOPIC_NEWSLETTERS)->addInfo(
'before queue chunk processing', 'before queue chunk processing',
['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id, 'found_subscribers_count' => count($found_subscribers)] ['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id, 'found_subscribers_count' => count($found_subscribers)]
); );
@ -138,12 +138,12 @@ class SendingQueue {
$_newsletter, $_newsletter,
$found_subscribers $found_subscribers
); );
$this->logger_factory->getLogger('newsletters')->addInfo( $this->logger_factory->getLogger(LoggerFactory::TOPIC_NEWSLETTERS)->addInfo(
'after queue chunk processing', 'after queue chunk processing',
['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id] ['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id]
); );
if ($queue->status === ScheduledTaskModel::STATUS_COMPLETED) { if ($queue->status === ScheduledTaskModel::STATUS_COMPLETED) {
$this->logger_factory->getLogger('newsletters')->addInfo( $this->logger_factory->getLogger(LoggerFactory::TOPIC_NEWSLETTERS)->addInfo(
'completed newsletter sending', 'completed newsletter sending',
['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id] ['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id]
); );

View File

@ -78,7 +78,7 @@ class Newsletter {
$this->stopNewsletterPreProcessing(sprintf('QUEUE-%d-RENDER', $sending_task->id)) : $this->stopNewsletterPreProcessing(sprintf('QUEUE-%d-RENDER', $sending_task->id)) :
$newsletter; $newsletter;
} }
$this->logger_factory->getLogger('newsletters')->addInfo( $this->logger_factory->getLogger(LoggerFactory::TOPIC_NEWSLETTERS)->addInfo(
'pre-processing newsletter', 'pre-processing newsletter',
['newsletter_id' => $newsletter->id, 'task_id' => $sending_task->task_id] ['newsletter_id' => $newsletter->id, 'task_id' => $sending_task->task_id]
); );
@ -109,7 +109,7 @@ class Newsletter {
$this->posts_task->getAlcPostsCount($rendered_newsletter, $newsletter) === 0 $this->posts_task->getAlcPostsCount($rendered_newsletter, $newsletter) === 0
) { ) {
// delete notification history record since it will never be sent // delete notification history record since it will never be sent
$this->logger_factory->getLogger('post-notifications')->addInfo( $this->logger_factory->getLogger(LoggerFactory::TOPIC_POST_NOTIFICATIONS)->addInfo(
'no posts in post notification, deleting it', 'no posts in post notification, deleting it',
['newsletter_id' => $newsletter->id, 'task_id' => $sending_task->task_id] ['newsletter_id' => $newsletter->id, 'task_id' => $sending_task->task_id]
); );

View File

@ -18,7 +18,7 @@ class Posts {
if ($newsletter->type !== NewsletterModel::TYPE_NOTIFICATION_HISTORY) { if ($newsletter->type !== NewsletterModel::TYPE_NOTIFICATION_HISTORY) {
return false; return false;
} }
$this->logger_factory->getLogger('post-notifications')->addInfo( $this->logger_factory->getLogger(LoggerFactory::TOPIC_POST_NOTIFICATIONS)->addInfo(
'extract and save posts - before', 'extract and save posts - before',
['newsletter_id' => $newsletter->id] ['newsletter_id' => $newsletter->id]
); );
@ -37,7 +37,7 @@ class Posts {
$newsletter_post->post_id = $post_id; $newsletter_post->post_id = $post_id;
$newsletter_post->save(); $newsletter_post->save();
} }
$this->logger_factory->getLogger('post-notifications')->addInfo( $this->logger_factory->getLogger(LoggerFactory::TOPIC_POST_NOTIFICATIONS)->addInfo(
'extract and save posts - after', 'extract and save posts - after',
['newsletter_id' => $newsletter->id, 'matched_posts_ids' => $matched_posts_ids] ['newsletter_id' => $newsletter->id, 'matched_posts_ids' => $matched_posts_ids]
); );

View File

@ -23,6 +23,9 @@ use MailPoetVendor\Monolog\Processor\WebProcessor;
* If WP_DEBUG is true additional information will be added to every log message. * If WP_DEBUG is true additional information will be added to every log message.
*/ */
class LoggerFactory { class LoggerFactory {
const TOPIC_NEWSLETTERS = 'newsletters';
const TOPIC_POST_NOTIFICATIONS = 'post-notifications';
const TOPIC_MSS = 'mss';
/** @var LoggerFactory */ /** @var LoggerFactory */
private static $instance; private static $instance;

View File

@ -46,7 +46,7 @@ class AutomatedLatestContent {
$current_user_id = WPFunctions::get()->getCurrentUserId(); $current_user_id = WPFunctions::get()->getCurrentUserId();
WPFunctions::get()->wpSetCurrentUser(0); WPFunctions::get()->wpSetCurrentUser(0);
$this->logger_factory->getLogger('post-notifications')->addInfo( $this->logger_factory->getLogger(LoggerFactory::TOPIC_POST_NOTIFICATIONS)->addInfo(
'loading automated latest content', 'loading automated latest content',
['args' => $args, 'posts_to_exclude' => $posts_to_exclude, 'newsletter_id' => $this->newsletter_id, 'newer_than_timestamp' => $this->newer_than_timestamp] ['args' => $args, 'posts_to_exclude' => $posts_to_exclude, 'newsletter_id' => $this->newsletter_id, 'newer_than_timestamp' => $this->newer_than_timestamp]
); );
@ -95,7 +95,7 @@ class AutomatedLatestContent {
WPFunctions::get()->addAction('pre_get_posts', [$this, 'ensureConsistentQueryType'], $filter_priority); WPFunctions::get()->addAction('pre_get_posts', [$this, 'ensureConsistentQueryType'], $filter_priority);
$this->_attachSentPostsFilter(); $this->_attachSentPostsFilter();
$this->logger_factory->getLogger('post-notifications')->addInfo( $this->logger_factory->getLogger(LoggerFactory::TOPIC_POST_NOTIFICATIONS)->addInfo(
'getting automated latest content', 'getting automated latest content',
['parameters' => $parameters] ['parameters' => $parameters]
); );
@ -170,7 +170,7 @@ class AutomatedLatestContent {
'post_date' => $post->post_date, 'post_date' => $post->post_date,
]; ];
} }
$this->logger_factory->getLogger('post-notifications')->addInfo( $this->logger_factory->getLogger(LoggerFactory::TOPIC_POST_NOTIFICATIONS)->addInfo(
'automated latest content loaded posts', 'automated latest content loaded posts',
['posts' => $posts_to_log] ['posts' => $posts_to_log]
); );

View File

@ -31,7 +31,7 @@ class PostNotificationScheduler {
} }
function transitionHook($new_status, $old_status, $post) { function transitionHook($new_status, $old_status, $post) {
$this->logger_factory->getLogger('post-notifications')->addInfo( $this->logger_factory->getLogger(LoggerFactory::TOPIC_POST_NOTIFICATIONS)->addInfo(
'transition post notification hook initiated', 'transition post notification hook initiated',
[ [
'post_id' => $post->ID, 'post_id' => $post->ID,
@ -47,7 +47,7 @@ class PostNotificationScheduler {
} }
function schedulePostNotification($post_id) { function schedulePostNotification($post_id) {
$this->logger_factory->getLogger('post-notifications')->addInfo( $this->logger_factory->getLogger(LoggerFactory::TOPIC_POST_NOTIFICATIONS)->addInfo(
'schedule post notification hook', 'schedule post notification hook',
['post_id' => $post_id] ['post_id' => $post_id]
); );
@ -95,7 +95,7 @@ class PostNotificationScheduler {
$sending_task->status = SendingQueue::STATUS_SCHEDULED; $sending_task->status = SendingQueue::STATUS_SCHEDULED;
$sending_task->scheduled_at = $next_run_date; $sending_task->scheduled_at = $next_run_date;
$sending_task->save(); $sending_task->save();
$this->logger_factory->getLogger('post-notifications')->addInfo( $this->logger_factory->getLogger(LoggerFactory::TOPIC_POST_NOTIFICATIONS)->addInfo(
'schedule post notification', 'schedule post notification',
['sending_task' => $sending_task->id(), 'scheduled_at' => $next_run_date] ['sending_task' => $sending_task->id(), 'scheduled_at' => $next_run_date]
); );

View File

@ -84,7 +84,7 @@ class API {
} }
function logCurlInformation($headers, $info) { function logCurlInformation($headers, $info) {
$this->logger_factory->getLogger('mss')->addInfo( $this->logger_factory->getLogger(LoggerFactory::TOPIC_MSS)->addInfo(
'requests-curl.after_request', 'requests-curl.after_request',
['headers' => $headers, 'curl_info' => $info] ['headers' => $headers, 'curl_info' => $info]
); );