Skip to content

Commit

Permalink
[Logger] Stack Trace Optional (#15)
Browse files Browse the repository at this point in the history
Co-authored-by: onairmarc <[email protected]>
  • Loading branch information
onairmarc and onairmarc authored Jul 26, 2024
1 parent 9058194 commit 404128b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ d1feb1300ad4b8237b2e41a8439a5bfa3915cf8f
eb2793b4c08a4aae2ff7cefc61c336778a33d6a8
5809f46c02bbe25c9799a6a4cd93c6f6ee395ece
0c213c750e950f6e9ee4e8f2632ec41ac29a70e0
f4e014138ae1c12a4f8a7f9778535ccb7bf1c440
5 changes: 5 additions & 0 deletions src/Common/src/Laravel/Config/phpgenesis.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
'version' => '2010-12-01',
],
'logger' => [
'exception' => [
'includeStackTrace' => env('PHPGENESIS_LOGGER_EXCEPTION_INCLUDE_STACK_TRACE', true),
],
],
];
17 changes: 15 additions & 2 deletions src/Logger/src/ExceptionLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
namespace PHPGenesis\Logger;

use Exception;
use Illuminate\Support\Facades\Config;
use PHPGenesis\Common\Composer\Providers\Laravel;

/** @experimental */
class ExceptionLogger
Expand Down Expand Up @@ -82,12 +84,23 @@ private static function buildMessage(string $message): string

private static function buildContext(Exception $exception, array $context = []): array
{
return array_merge([
$mergedContext = array_merge([
'exception.message' => $exception->getMessage(),
'exception.code' => $exception->getCode(),
'exception.file' => $exception->getFile(),
'exception.line' => $exception->getLine(),
'exception.trace' => $exception->getTraceAsString(),
], $context);

if (Laravel::installed() && (Config::get('phpgenesis.logger.exception.includeStackTrace'))) {
$mergedContext['exception.trace'] = $exception->getTrace();

return $mergedContext;
}

if (!Laravel::installed()) {
$mergedContext['exception.trace'] = $exception->getTrace();
}

return $mergedContext;
}
}

0 comments on commit 404128b

Please sign in to comment.