MainLogger: implement BufferedLogger

This commit is contained in:
Dylan K. Taylor 2020-04-01 20:09:42 +01:00
parent 64d5320ac9
commit f5cd87ac95

View File

@ -38,7 +38,7 @@ use function trim;
use const PHP_EOL; use const PHP_EOL;
use const PTHREADS_INHERIT_NONE; use const PTHREADS_INHERIT_NONE;
class MainLogger extends \AttachableThreadedLogger{ class MainLogger extends \AttachableThreadedLogger implements \BufferedLogger{
/** @var string */ /** @var string */
protected $logFile; protected $logFile;
@ -149,7 +149,7 @@ class MainLogger extends \AttachableThreadedLogger{
$trace = $e->getTrace(); $trace = $e->getTrace();
} }
$this->synchronized(function() use ($e, $trace) : void{ $this->buffer(function() use ($e, $trace) : void{
$this->critical(self::printExceptionMessage($e)); $this->critical(self::printExceptionMessage($e));
foreach(Utils::printableTrace($trace) as $line){ foreach(Utils::printableTrace($trace) as $line){
$this->debug($line, true); $this->debug($line, true);
@ -210,6 +210,13 @@ class MainLogger extends \AttachableThreadedLogger{
} }
} }
/**
* @phpstan-param \Closure() : void $c
*/
public function buffer(\Closure $c) : void{
$this->synchronized($c);
}
public function shutdown() : void{ public function shutdown() : void{
$this->shutdown = true; $this->shutdown = true;
$this->notify(); $this->notify();