forked from php-censor/php-censor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoggingCommand.php
More file actions
74 lines (63 loc) · 1.81 KB
/
Copy pathLoggingCommand.php
File metadata and controls
74 lines (63 loc) · 1.81 KB
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
<?php
namespace PHPCensor\Command;
use Monolog\Handler\AbstractHandler;
use Monolog\Logger;
use PHPCensor\Logging\OutputLogHandler;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
abstract class LoggingCommand extends Command
{
/**
* @var Logger
*/
protected $logger;
/**
* @param \Monolog\Logger $logger
* @param string $name
*/
public function __construct(Logger $logger, $name = null)
{
parent::__construct($name);
$this->logger = $logger;
}
/**
* @param OutputInterface $output
*/
protected function configureLogging(OutputInterface $output)
{
$level = Logger::ERROR;
if ($output->isDebug()) {
$level = Logger::DEBUG;
} elseif ($output->isVeryVerbose()) {
$level = Logger::INFO;
} elseif ($output->isVerbose()) {
$level = Logger::NOTICE;
}
$handlers = $this->logger->getHandlers();
foreach ($handlers as $handler) {
if ($handler instanceof AbstractHandler) {
$handler->setLevel($level);
}
}
if (!$output->isQuiet()) {
$this->logger->pushHandler(
new OutputLogHandler($output, $level)
);
}
if ($output->isDebug()) {
$this->logger->notice(
sprintf('Command "%s" started in debug mode (-vvv).', $this->getName())
);
define('DEBUG_MODE', true);
}
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->configureLogging($output);
}
}