2016-07-15 22:26:08 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Handler.php
|
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
|
|
*
|
|
|
|
* This software may be modified and distributed under the terms
|
|
|
|
* of the MIT license. See the LICENSE file for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types = 1);
|
|
|
|
|
|
|
|
namespace FireflyIII\Import\Logging;
|
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Monolog\Handler\AbstractProcessingHandler;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class CommandHandler
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Import\Logging
|
|
|
|
*/
|
|
|
|
class CommandHandler extends AbstractProcessingHandler
|
|
|
|
{
|
|
|
|
|
|
|
|
/** @var Command */
|
|
|
|
private $command;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler constructor.
|
|
|
|
*
|
|
|
|
* @param Command $command
|
|
|
|
*/
|
|
|
|
public function __construct(Command $command)
|
|
|
|
{
|
2016-08-11 18:44:11 +02:00
|
|
|
parent::__construct();
|
2016-07-15 22:26:08 +02:00
|
|
|
$this->command = $command;
|
2016-08-11 18:44:11 +02:00
|
|
|
$this->changeLevel(env('LOG_LEVEL', 'debug'));
|
2016-07-15 22:26:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes the record down to the log of the implementing handler
|
|
|
|
*
|
|
|
|
* @param array $record
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function write(array $record)
|
|
|
|
{
|
2016-08-11 18:44:11 +02:00
|
|
|
$this->command->line((string)trim($record['formatted']));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $level
|
|
|
|
*/
|
|
|
|
private function changeLevel(string $level)
|
|
|
|
{
|
2016-09-25 08:59:27 +02:00
|
|
|
$level = strtoupper($level);
|
|
|
|
if (defined(sprintf('Logger::%s', $level))) {
|
|
|
|
$this->setLevel(constant(sprintf('Logger::%s', $level)));
|
2016-08-11 18:44:11 +02:00
|
|
|
}
|
2016-07-15 22:26:08 +02:00
|
|
|
}
|
2016-08-12 15:10:03 +02:00
|
|
|
}
|