Skip to content

Commit

Permalink
Aggiunta la possibilità di impostare il modo di ottenere le informazi…
Browse files Browse the repository at this point in the history
…oni di un utente loggato
  • Loading branch information
Armando Caprio committed Apr 2, 2024
1 parent e243043 commit 356eb22
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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`:
Expand Down Expand Up @@ -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)
9 changes: 6 additions & 3 deletions src/Phalcon/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
}
5 changes: 5 additions & 0 deletions src/Phalcon/KrakenLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}

Expand Down

0 comments on commit 356eb22

Please sign in to comment.