Skip to content

Commit

Permalink
Keep in memory only 1024 messages of each type
Browse files Browse the repository at this point in the history
  • Loading branch information
Vítězslav Dvořák committed May 29, 2024
1 parent 9b39b01 commit 31718e3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Ease/Logger/ToMemory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

class ToMemory extends \Ease\Atom implements Loggingable
{
/**
* Number of messages to keep
* @var int
*/
public $capacity = 1024;

/**
* Předvolená metoda logování.
*
Expand Down Expand Up @@ -99,6 +105,9 @@ public function addToLog($caller, $message, $type = 'message')
{
++$this->messageID;
self::$statusMessages[$type][Message::getCallerName($caller) . $this->messageID] = $message;
if (count(self::$statusMessages[$type]) > $this->capacity) {
self::$statusMessages[$type] = array_slice(self::$statusMessages[$type], $this->capacity);
}
return strlen($message);
}

Expand Down

0 comments on commit 31718e3

Please sign in to comment.