More updates to stop using dev or alpha or beta versions.
[yaffs-website] / vendor / consolidation / robo / src / Log / RoboLogStyle.php
1 <?php
2 namespace Robo\Log;
3
4 use Robo\Common\TimeKeeper;
5 use Consolidation\Log\LogOutputStyler;
6
7 /**
8  * Robo Log Styler.
9  */
10 class RoboLogStyle extends LogOutputStyler
11 {
12     const TASK_STYLE_SIMULATED = 'options=reverse;bold';
13
14     /**
15      * RoboLogStyle constructor.
16      *
17      * @param array $labelStyles
18      * @param array $messageStyles
19      */
20     public function __construct($labelStyles = [], $messageStyles = [])
21     {
22         parent::__construct($labelStyles, $messageStyles);
23
24         $this->labelStyles += [
25             RoboLogLevel::SIMULATED_ACTION => self::TASK_STYLE_SIMULATED,
26         ];
27         $this->messageStyles += [
28             RoboLogLevel::SIMULATED_ACTION => '',
29         ];
30     }
31
32     /**
33      * Log style customization for Robo: replace the log level with
34      * the task name.
35      *
36      * @param string $level
37      * @param string $message
38      * @param array $context
39      *
40      * @return string
41      */
42     protected function formatMessageByLevel($level, $message, $context)
43     {
44         $label = $level;
45         if (array_key_exists('name', $context)) {
46             $label = $context['name'];
47         }
48         return $this->formatMessage($label, $message, $context, $this->labelStyles[$level], $this->messageStyles[$level]);
49     }
50
51     /**
52      * Log style customization for Robo: add the time indicator to the
53      * end of the log message if it exists in the context.
54      *
55      * @param string $label
56      * @param string $message
57      * @param array $context
58      * @param string $taskNameStyle
59      * @param string $messageStyle
60      *
61      * @return string
62      */
63     protected function formatMessage($label, $message, $context, $taskNameStyle, $messageStyle = '')
64     {
65         $message = parent::formatMessage($label, $message, $context, $taskNameStyle, $messageStyle);
66
67         if (array_key_exists('time', $context) && !empty($context['time']) && array_key_exists('timer-label', $context)) {
68             $duration = TimeKeeper::formatDuration($context['time']);
69             $message .= ' ' . $context['timer-label'] . ' ' . $this->wrapFormatString($duration, 'fg=yellow');
70         }
71
72         return $message;
73     }
74 }