Maslosoft Cli Shared API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
<?php
/**
* This software package is licensed under `AGPL, Commercial` license[s].
*
* @package maslosoft/cli-shared
* @license AGPL, Commercial
*
* @copyright Copyright (c) Peter Maselkowski <pmaselkowski@gmail.com>
*/
namespace Maslosoft\Cli\Shared\Log;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Logger
*
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
*/
class Logger extends Base implements LoggerInterface
{
/**
* Output
* @var OutputInterface
*/
private $output = null;
public function __construct(OutputInterface $output)
{
$this->output = $output;
}
protected function add($level, $message)
{
if ($this->output->isQuiet())
{
return;
}
$patterns = [
// Backtics
'~`(.+?)`~',
// Errors
'~(Error\W)~',
// Warnings
'~(Warning\W)~'
];
$replacements = [
// Backtics to info block
'<info>$1</info>',
// Make errors shine
'<error>$1</error>',
// Make warnings noticable
'<comment>$1</comment>',
];
$message = preg_replace($patterns, $replacements, $message);
// Always show high level messages:
// emergency
// alert
// critical
// error
//
if ($level === self::LevelHigh)
{
$this->output->writeln($message);
return;
}
// Mid and above:
// emergency
// alert
// critical
// error
// --
// warning
// notice
//
if ($this->output->isVerbose() && $level > self::LevelLow)
{
$this->output->writeln($message);
return;
}
// Low and above:
// emergency
// alert
// critical
// error
// --
// warning
// notice
// --
// info
//
if ($this->output->isVeryVerbose() && $level > self::LevelDebug)
{
$this->output->writeln($message);
return;
}
// Show all messages on debug mode
if ($this->output->isDebug())
{
$this->output->writeln($message);
return;
}
}
}
API documentation generated by ApiGen