Skip to content

Commit

Permalink
Add parameters for truncated sizes (#25)
Browse files Browse the repository at this point in the history
* Add parameters for truncated sizes

* Update MultiRecordArrayHandler.php
  • Loading branch information
gmponos authored Aug 30, 2019
1 parent 2adbb89 commit e686ab9
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/Handler/MultiRecordArrayHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,26 @@
*/
final class MultiRecordArrayHandler extends AbstractHandler
{
/**
* @var int
*/
private $truncateSize;

/**
* @var int
*/
private $summarySize;

/**
* @param LogLevelStrategyInterface|null $logLevelStrategy
* @param int $truncateSize If the body of the request/response is greater than the size of this integer the body will be truncated
* @param int $summarySize The size to use for the summary of a truncated body
*/
public function __construct(LogLevelStrategyInterface $logLevelStrategy = null)
public function __construct(LogLevelStrategyInterface $logLevelStrategy = null, int $truncateSize = 3500, int $summarySize = 200)
{
$this->logLevelStrategy = $logLevelStrategy === null ? $this->getDefaultStrategy() : $logLevelStrategy;
$this->truncateSize = $truncateSize;
$this->summarySize = $summarySize;
}

/**
Expand Down Expand Up @@ -149,8 +163,8 @@ private function formatBody(MessageInterface $message, array $options)
return 'Body contains sensitive information therefore it is not included.';
}

if ($stream->getSize() >= 3500) {
$summary = $stream->read(200) . ' (truncated...)';
if ($stream->getSize() >= $this->truncateSize) {
$summary = $stream->read($this->summarySize) . ' (truncated...)';
$stream->rewind();
return $summary;
}
Expand Down

1 comment on commit e686ab9

@quberok
Copy link

@quberok quberok commented on e686ab9 Sep 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thanks a lot!

Please sign in to comment.