1
0
Fork 0
mirror of synced 2024-09-28 07:21:35 +12:00

Fixed worker logger

This commit is contained in:
Matej Baco 2021-12-06 13:55:59 +01:00
parent c6c555b763
commit 4d8c2e3cdb
3 changed files with 18 additions and 15 deletions

View file

@ -2,6 +2,8 @@
use Appwrite\Extend\PDO;
use Utopia\App;
use Utopia\CLI\Console;
use Utopia\Logger\Log;
use Appwrite\Resque\Worker;
/** @var Utopia\Registry\Registry $register */
@ -33,18 +35,16 @@ $register->set('cache', function () { // Register cache connection
return $redis;
});
Worker::error(function ($error, $action) use ($register) {
Worker::error(function ($error, $action, $workerType, $optionalExtras) use ($register) {
/** @var Throwable|Exception $error */
/** @var string $action */
/** @var string $workerType */
$logger = $register->get('logger');
if($logger) {
$version = App::getEnv('_APP_VERSION', 'UNKNOWN');
$className = \get_called_class();
$workerType = $className;
$log = new Log();
$log->setNamespace("worker-" . $workerType);
@ -60,8 +60,10 @@ Worker::error(function ($error, $action) use ($register) {
$log->addExtra('file', $error->getFile());
$log->addExtra('line', $error->getLine());
$log->addExtra('trace', $error->getTraceAsString());
// $log->addExtra('args', $this->args);
// TODO: Test worker error for get_called_class and if args are in trace. What about JWT in args? Other secrets? What about realtime/API?
if($optionalExtras) {
$log->addExtra('args', $optionalExtras);
}
$action = 'worker.' . $workerType . '.' . $action;
$log->setAction($action);

6
composer.lock generated
View file

@ -2066,10 +2066,10 @@
"source": {
"type": "git",
"url": "https://github.com/utopia-php/logger",
"reference": "c50b16a864857cfad381917b2e6f4991f1bccc3e"
"reference": "e67eafc1edb8729c463275b81ff4e870eb30c314"
},
"require": {
"php": ">=7.4"
"php": ">=8.0"
},
"require-dev": {
"phpunit/phpunit": "^9.3",
@ -2113,7 +2113,7 @@
"utopia",
"warnings"
],
"time": "2021-11-29T11:40:17+00:00"
"time": "2021-12-06T11:18:07+00:00"
},
{
"name": "utopia-php/orchestration",

View file

@ -3,6 +3,7 @@
namespace Appwrite\Resque;
use Exception;
use function var_dump;
class Worker
{
@ -75,8 +76,8 @@ class Worker
try {
$this->init();
} catch(\Throwable $error) {
foreach ($this->errorCallbacks as $errorCallback) {
$errorCallback($error, "init");
foreach (self::$errorCallbacks as $errorCallback) {
$errorCallback($error, "init", $this->getName());
}
throw $error;
@ -94,8 +95,8 @@ class Worker
try {
$this->run();
} catch(\Throwable $error) {
foreach ($this->errorCallbacks as $errorCallback) {
$errorCallback($error, "run");
foreach (self::$errorCallbacks as $errorCallback) {
$errorCallback($error, "run", $this->getName(), $this->args);
}
throw $error;
@ -113,8 +114,8 @@ class Worker
try {
$this->shutdown();
} catch(\Throwable $error) {
foreach ($this->errorCallbacks as $errorCallback) {
$errorCallback($error, "shutdown");
foreach (self::$errorCallbacks as $errorCallback) {
$errorCallback($error, "shutdown", $this->getName());
}
throw $error;