From 356eb22ed4754d5e3840f87a60b3bb1cd7a4d63c Mon Sep 17 00:00:00 2001 From: Armando Caprio Date: Tue, 2 Apr 2024 16:26:33 +0200 Subject: [PATCH] =?UTF-8?q?Aggiunta=20la=20possibilit=C3=A0=20di=20imposta?= =?UTF-8?q?re=20il=20modo=20di=20ottenere=20le=20informazioni=20di=20un=20?= =?UTF-8?q?utente=20loggato?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +++++++ src/Phalcon/Config/Config.php | 9 ++++++--- src/Phalcon/KrakenLogger.php | 5 +++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 420f0b6..5d42e39 100644 --- a/README.md +++ b/README.md @@ -176,6 +176,7 @@ From the file created in `config/kraken.php` you can edit: - The environments that trigger the ExceptionHandler - The type code and builder class of an exception report - The type code and builder class of an log report +- Signed in user information For more details see the [configuration file](/src/Laravel/config/config.php) @@ -227,6 +228,11 @@ $krakenHandler->addHideDataKey( getenv( 'DATABASE_PASSWORD' ) ); $krakenHandler->addHideDataKey( 'KEY_CLI_ACCESS' ); ``` +By default the package does not send the information of the logged in user, they can be added by setting `userDataGetter` property in the configuration object, with a callable that returns this information + +For more details see [phalcon customization](#customization-phalcon) + + ### Logger Usage (Phalcon) It is possible to send single reports and logs via KrakenLogger using `KrakenService`: @@ -265,5 +271,6 @@ The config object can be customized for change: - The type code and builder class of an exception report - The builder class of an php error report - The type code and builder class of an log report +- Signed in user information For more details see the [configuration class](/src/Phalcon/Config/Config.php) diff --git a/src/Phalcon/Config/Config.php b/src/Phalcon/Config/Config.php index 9348830..af578fa 100755 --- a/src/Phalcon/Config/Config.php +++ b/src/Phalcon/Config/Config.php @@ -2,6 +2,7 @@ namespace Shellrent\KrakenClient\Phalcon\Config; +use Closure; use Shellrent\KrakenClient\Phalcon\ReportBuilder\ExceptionBuilder; use Shellrent\KrakenClient\Phalcon\ReportBuilder\FatalErrorBuilder; use Shellrent\KrakenClient\Phalcon\ReportBuilder\LogBuilder; @@ -15,10 +16,11 @@ class Config { public LogBuilder $logBuilder; public string $exceptionReportType; public string $logReportType; + public ?Closure $userDataGetter = null; + public static function default(): self { $config = new self(); - $config->apiEndpoint = getenv( 'KRAKEN_API_ENDPOINT' ) ?? 'localhost'; $config->apiToken = getenv( 'KRAKEN_API_TOKEN' ) ?? 'token'; $config->verifySsl = true; @@ -28,11 +30,12 @@ public static function default(): self { $config->exceptionReportType = 'EXCEPTION'; $config->logReportType = 'LOG'; - return $config; } public function __clone() { - //TODO + $this->exceptionBuilder = clone $this->exceptionBuilder; + $this->fatalErrorBuilder = clone $this->fatalErrorBuilder; + $this->logBuilder = clone $this->logBuilder; } } \ No newline at end of file diff --git a/src/Phalcon/KrakenLogger.php b/src/Phalcon/KrakenLogger.php index 7afd7b4..4b497dd 100755 --- a/src/Phalcon/KrakenLogger.php +++ b/src/Phalcon/KrakenLogger.php @@ -22,6 +22,11 @@ public function __construct( Config $config ) { } protected function dispatch( ReportBuilder $report ): void { + if( $this->config->userDataGetter ) { + $userData = call_user_func( $this->config->userDataGetter ); + $report->addExtraInfo( 'user', $userData ); + } + $this->client->sendReport( $report->getData() ); }