Closed utdrmac closed 8 months ago
It is worth noting that only normal logs are written there, all error logs go to error still.
$this->logger->info($message, ['scope' => 'queue']);
We will need to find out why the scopes part doesnt work
It is worth noting that only normal logs are written there, all error logs go to error still.
'levels' => ['emergency', 'alert', 'critical', 'error', 'warning', 'notice', 'info', 'debug'],
Why wouldn't errors go into this log when I've specifically configured it to do so? I want everything in 1 log location so I don't have to go searching through 5 different files looking for problems.
Because from cake3 to 4 CakePHP fundamentially changed how logging works From direct loggin to indirect one (listening) via scopes.
https://github.com/dereuromark/cakephp-queue/blob/master/src/Queue/Task/EmailTask.php#L151 and other places would have to be adjusted to have the scope added
Do you want to make a PR with suggested changes that make it work for you?
It's worth to mention, that the logging is not always as it seems in the PHP-CLI. Basically, the CakePHP console looks to a pre-defined logger (in your app.php config) which is an instance of ConsoleLog. If your logger (as it seems) only extends filelog, it is not regarded as a consolelog. That means, you always end up with the cli logs.
If you make your logger extend the ConsoleLog, you might end up with logging the errors in your file log, but not in the console (stdout or stderr) anymore. What I use is a combined logger: I modified the ConsoleLog::log() function, to log it to my own Logger (extending FileLog) and I called the parent::log() to still receive the log in your stdout/stderr
Example: (please note, the QueueLogger is an implementation of FileLog)
namespace App\Queue\Log;
use Cake\Core\Configure;
use Cake\Log\Engine\BaseLog;
use Cake\Log\Engine\ConsoleLog;
class CombinedLogger extends ConsoleLog {
/**
* @var BaseLog[]
*/
protected array $loggers = [];
public function __construct(array $config = [])
{
parent::__construct($config);
$this->addLogger(QueueLogger::class, $config);
}
public function getLogger(string $fqn) : BaseLog
{
return $this->loggers[$fqn];
}
public function addLogger(string $fqn, array $config = [])
{
$this->loggers[$fqn] = new $fqn($config);
}
public function log($level, string|\Stringable $message, array $context = []): void
{
foreach ($this->loggers as $logger) {
$logger->log($level,$message,$context);
}
if (Configure::read('debug', FALSE)) {
parent::log($level, $message, $context);
}
}
}
And I only added this log configuration for the CLI interface, so in bootstrap_cli.php
I added
Configure::write('Log.combined', [
'className' => CombinedLogger::class,
'path' => LOGS.'Queue'.DS,
'file' => 'task',
'url' => env('LOG_COMBINED_URL', null),
'scopes' => null,
'levels' => ['notice', 'info', 'debug','warning', 'error', 'critical', 'alert', 'emergency'],
]);
Do you think anything needs to be done still on queue side? Or can we close this?
I am now preparing the new major release for the open PR, so best we address any bugs beforehand to be available for both majors.
I think this is per design so in CakePHP. Not something that should be solved in this repo, nor do I think it is a bug in the Queue repo.
Following docs here, https://github.com/dereuromark/cakephp-queue/blob/master/docs/sections/misc.md
I added this to my config/app.php:
When I executed the worker,
$ bin/cake queue run -t ExportNotionDoc -v
, I expected the logs to be written tologs/queue.log
but instead the logs were output to the terminal and additionally written tologs/cli-debug.log
.The config docs do not mention any logging options, so I'm not sure what else I need to do to get logs working to my location.
CakePHP5's bootstrap_cli.php overrides the location of debug level logs:
So it makes sense that when I execute something on CLI, the logs go there. But I explicitly set the queue logs to a different file so this CLI override shouldn't matter.