. */ declare(strict_types=1); namespace FireflyIII\Import\Logging; use Illuminate\Console\Command; use Monolog\Handler\AbstractProcessingHandler; /** * Class CommandHandler. */ class CommandHandler extends AbstractProcessingHandler { /** @var Command */ private $command; /** * Handler constructor. * * @param Command $command */ public function __construct(Command $command) { parent::__construct(); $this->command = $command; $this->changeLevel(env('APP_LOG_LEVEL', 'info')); } /** * Writes the record down to the log of the implementing handler. * * @param array $record */ protected function write(array $record) { $this->command->line((string)trim($record['formatted'])); } /** * @param string $level */ private function changeLevel(string $level) { $level = strtoupper($level); $reference = sprintf('\Monolog\Logger::%s', $level); if (defined($reference)) { $this->setLevel(constant($reference)); } } }