Files
firefly-iii/app/Import/Logging/CommandHandler.php

77 lines
1.9 KiB
PHP
Raw Normal View History

2016-07-15 22:26:08 +02:00
<?php
/**
* CommandHandler.php
2017-10-21 08:40:00 +02:00
* Copyright (c) 2017 thegrumpydictator@gmail.com
2016-07-15 22:26:08 +02:00
*
2017-10-21 08:40:00 +02:00
* This file is part of Firefly III.
*
2017-10-21 08:40:00 +02:00
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
2016-07-15 22:26:08 +02:00
*/
declare(strict_types=1);
2016-07-15 22:26:08 +02:00
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;
2017-07-15 10:26:16 +02:00
$this->changeLevel(env('APP_LOG_LEVEL', 'info'));
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)
{
2017-07-15 10:26:16 +02:00
$level = strtoupper($level);
$reference = sprintf('\Monolog\Logger::%s', $level);
if (defined($reference)) {
$this->setLevel(constant($reference));
2016-08-11 18:44:11 +02:00
}
2016-07-15 22:26:08 +02:00
}
2016-08-12 15:10:03 +02:00
}