Skip to content

Commit 6219628

Browse files
committed
Allow use of Monolog 2.x (as well as 1.x)
No changes needed to the Logger class itself, as the StreamHandler constructor is compatible in 2.x. Usages of non-PSR-standard e.g. Logger->addInfo() methods are replaced with PSR-standard e.g. Logger->info() calls, as both exist in 1.x and the former are removed in Monolog 2. See https://github.com/Seldaek/monolog/blob/main/UPGRADE.md
1 parent a9baeb0 commit 6219628

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
],
2121
"require": {
2222
"php": ">=5.3.0",
23-
"monolog/monolog": "~1.3",
23+
"monolog/monolog": "~1.3||~2",
2424
"clio/clio": "0.1.*"
2525
},
2626
"require-dev": {

demo/queues/BeanstalkSampleQueue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function getJob($jobId = null)
3838

3939
public function updateJob($jobId = null, $resultData = null)
4040
{
41-
$this->resultLog->addInfo('Result: ID='.$jobId, $resultData);
41+
$this->resultLog->info('Result: ID='.$jobId, $resultData);
4242
}
4343

4444
public function clearJob($jobId = null)

src/PHPQueue/Runner.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected function checkAndCycleLog()
8383
$this->current_log_check++;
8484
if ($this->current_log_check > $this->max_check_interval) {
8585
if ($this->current_date != date('Ymd')) {
86-
$this->logger->addAlert("Cycling log file now.");
86+
$this->logger->alert("Cycling log file now.");
8787
$this->logger = Logger::cycleLog(
8888
$this->queue_name
8989
, $this->log_level
@@ -101,11 +101,11 @@ public function workJob()
101101
try {
102102
$newJob = Base::getJob($this->queue);
103103
} catch (\Exception $ex) {
104-
$this->logger->addError($ex->getMessage());
104+
$this->logger->error($ex->getMessage());
105105
$sleepTime = self::RUN_USLEEP * 5;
106106
}
107107
if (empty($newJob)) {
108-
$this->logger->addNotice("No Job found.");
108+
$this->logger->notice("No Job found.");
109109
$sleepTime = self::RUN_USLEEP * 10;
110110
} else {
111111
try {
@@ -115,7 +115,7 @@ public function workJob()
115115
if (is_string($newJob->worker)) {
116116
$result_data = $this->processWorker($newJob->worker, $newJob);
117117
} elseif (is_array($newJob->worker)) {
118-
$this->logger->addInfo(sprintf("Running chained new job (%s) with workers", $newJob->job_id), $newJob->worker);
118+
$this->logger->info(sprintf("Running chained new job (%s) with workers", $newJob->job_id), $newJob->worker);
119119
foreach ($newJob->worker as $worker_name) {
120120
$result_data = $this->processWorker($worker_name, $newJob);
121121
$newJob->data = $result_data;
@@ -124,22 +124,22 @@ public function workJob()
124124

125125
return Base::updateJob($this->queue, $newJob->job_id, $result_data);
126126
} catch (\Exception $ex) {
127-
$this->logger->addError($ex->getMessage());
128-
$this->logger->addInfo(sprintf('Releasing job (%s).', $newJob->job_id));
127+
$this->logger->error($ex->getMessage());
128+
$this->logger->info(sprintf('Releasing job (%s).', $newJob->job_id));
129129
$this->queue->releaseJob($newJob->job_id);
130130
$sleepTime = self::RUN_USLEEP * 5;
131131
}
132132
}
133-
$this->logger->addInfo('Sleeping ' . ceil($sleepTime / 1000000) . ' seconds.');
133+
$this->logger->info('Sleeping ' . ceil($sleepTime / 1000000) . ' seconds.');
134134
usleep($sleepTime);
135135
}
136136

137137
protected function processWorker($worker_name, $new_job)
138138
{
139-
$this->logger->addInfo(sprintf("Running new job (%s) with worker: %s", $new_job->job_id, $worker_name));
139+
$this->logger->info(sprintf("Running new job (%s) with worker: %s", $new_job->job_id, $worker_name));
140140
$worker = Base::getWorker($worker_name);
141141
Base::workJob($worker, $new_job);
142-
$this->logger->addInfo(sprintf('Worker is done. Updating job (%s). Result:', $new_job->job_id), $worker->result_data);
142+
$this->logger->info(sprintf('Worker is done. Updating job (%s). Result:', $new_job->job_id), $worker->result_data);
143143

144144
return $worker->result_data;
145145
}

0 commit comments

Comments
 (0)