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) {
$this->logger_factory->getLogger('post-notifications')->addInfo(
$this->logger_factory->getLogger(LoggerFactory::TOPIC_POST_NOTIFICATIONS)->addInfo(
'process post notification in scheduler',
['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id]
);
// ensure that segments exist
$segments = $newsletter->segments()->findMany();
if (empty($segments)) {
$this->logger_factory->getLogger('post-notifications')->addInfo(
$this->logger_factory->getLogger(LoggerFactory::TOPIC_POST_NOTIFICATIONS)->addInfo(
'post notification no segments',
['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id]
);
@ -102,7 +102,7 @@ class Scheduler {
$subscribers_count = $this->subscribers_finder->addSubscribersToTaskFromSegments($queue->task(), $segments);
if (empty($subscribers_count)) {
$this->logger_factory->getLogger('post-notifications')->addInfo(
$this->logger_factory->getLogger(LoggerFactory::TOPIC_POST_NOTIFICATIONS)->addInfo(
'post notification no subscribers',
['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id]
);
@ -119,7 +119,7 @@ class Scheduler {
$queue->save();
// update notification status
$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',
['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id]
);

View File

@ -66,7 +66,7 @@ class SendingQueue {
if (!$queue instanceof SendingTask) continue;
ScheduledTaskModel::touchAllByIds([$queue->task_id]);
$this->logger_factory->getLogger('newsletters')->addInfo(
$this->logger_factory->getLogger(LoggerFactory::TOPIC_NEWSLETTERS)->addInfo(
'sending queue processing',
['task_id' => $queue->task_id]
);
@ -77,7 +77,7 @@ class SendingQueue {
// pre-process newsletter (render, replace shortcodes/links, etc.)
$newsletter = $this->newsletter_task->preProcessNewsletter($newsletter, $queue);
if (!$newsletter) {
$this->logger_factory->getLogger('newsletters')->addInfo(
$this->logger_factory->getLogger(LoggerFactory::TOPIC_NEWSLETTERS)->addInfo(
'delete task in sending queue',
['task_id' => $queue->task_id]
);
@ -98,7 +98,7 @@ class SendingQueue {
// get subscribers
$subscriber_batches = new BatchIterator($queue->task_id, $this->batch_size);
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',
['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id, 'subscriber_batch_count' => count($subscribers_to_process_ids)]
);
@ -129,7 +129,7 @@ class SendingQueue {
continue;
}
}
$this->logger_factory->getLogger('newsletters')->addInfo(
$this->logger_factory->getLogger(LoggerFactory::TOPIC_NEWSLETTERS)->addInfo(
'before queue chunk processing',
['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id, 'found_subscribers_count' => count($found_subscribers)]
);
@ -138,12 +138,12 @@ class SendingQueue {
$_newsletter,
$found_subscribers
);
$this->logger_factory->getLogger('newsletters')->addInfo(
$this->logger_factory->getLogger(LoggerFactory::TOPIC_NEWSLETTERS)->addInfo(
'after queue chunk processing',
['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id]
);
if ($queue->status === ScheduledTaskModel::STATUS_COMPLETED) {
$this->logger_factory->getLogger('newsletters')->addInfo(
$this->logger_factory->getLogger(LoggerFactory::TOPIC_NEWSLETTERS)->addInfo(
'completed newsletter sending',
['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)) :
$newsletter;
}
$this->logger_factory->getLogger('newsletters')->addInfo(
$this->logger_factory->getLogger(LoggerFactory::TOPIC_NEWSLETTERS)->addInfo(
'pre-processing newsletter',
['newsletter_id' => $newsletter->id, 'task_id' => $sending_task->task_id]
);
@ -109,7 +109,7 @@ class Newsletter {
$this->posts_task->getAlcPostsCount($rendered_newsletter, $newsletter) === 0
) {
// 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',
['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) {
return false;
}
$this->logger_factory->getLogger('post-notifications')->addInfo(
$this->logger_factory->getLogger(LoggerFactory::TOPIC_POST_NOTIFICATIONS)->addInfo(
'extract and save posts - before',
['newsletter_id' => $newsletter->id]
);
@ -37,7 +37,7 @@ class Posts {
$newsletter_post->post_id = $post_id;
$newsletter_post->save();
}
$this->logger_factory->getLogger('post-notifications')->addInfo(
$this->logger_factory->getLogger(LoggerFactory::TOPIC_POST_NOTIFICATIONS)->addInfo(
'extract and save posts - after',
['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.
*/
class LoggerFactory {
const TOPIC_NEWSLETTERS = 'newsletters';
const TOPIC_POST_NOTIFICATIONS = 'post-notifications';
const TOPIC_MSS = 'mss';
/** @var LoggerFactory */
private static $instance;

View File

@ -46,7 +46,7 @@ class AutomatedLatestContent {
$current_user_id = WPFunctions::get()->getCurrentUserId();
WPFunctions::get()->wpSetCurrentUser(0);
$this->logger_factory->getLogger('post-notifications')->addInfo(
$this->logger_factory->getLogger(LoggerFactory::TOPIC_POST_NOTIFICATIONS)->addInfo(
'loading automated latest content',
['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);
$this->_attachSentPostsFilter();
$this->logger_factory->getLogger('post-notifications')->addInfo(
$this->logger_factory->getLogger(LoggerFactory::TOPIC_POST_NOTIFICATIONS)->addInfo(
'getting automated latest content',
['parameters' => $parameters]
);
@ -170,7 +170,7 @@ class AutomatedLatestContent {
'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',
['posts' => $posts_to_log]
);

View File

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

View File

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