-
-
Notifications
You must be signed in to change notification settings - Fork 634
/
Output.php
85 lines (74 loc) · 2.05 KB
/
Output.php
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
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Console\Output;
use Monolog\Logger;
use Symfony\Component\Console\Output\ConsoleOutput;
/**
* A custom output class for our Console object that supports writing to the log.
*/
class Output extends ConsoleOutput
{
/** @var Logger Object used to log system and debug messages to. */
protected $logger;
/**
* Sets a logger object to write information to.
*
* @param Logger $logger
*/
public function setLogger(Logger $logger)
{
$this->logger = $logger;
}
/**
* Returns the object where is being logged to.
*
* @return Logger
*/
public function getLogger()
{
return $this->logger;
}
/**
* Executes a callable piece of code and writes an entry to the log detailing how long it took.
*
* @param string $message
* @param callable $operation
* @param array $arguments
*
* @return void
*/
public function writeTimedLog($message, $operation, array $arguments = array())
{
$this->write(sprintf('%-66.66s .. ', $message));
$timerStart = microtime(true);
call_user_func_array($operation, $arguments);
$this->writeln(sprintf('%8.3fs', microtime(true) - $timerStart));
}
/**
* Write an entry to the console and to the provided logger.
*
* @param array|string $messages
* @param bool $newline
* @param int $type
*
* @return void
*/
public function write($messages, $newline = false, $type = 0)
{
$messages = (array) $messages;
if ($this->getLogger()) {
foreach ($messages as $message) {
$this->getLogger()->info($this->getFormatter()->format(strip_tags($message)));
}
}
parent::write($messages, $newline, $type);
}
}