4 use Robo\Common\TimeKeeper;
5 use Consolidation\Log\LogOutputStyler;
10 class RoboLogStyle extends LogOutputStyler
12 const TASK_STYLE_SIMULATED = 'options=reverse;bold';
15 * RoboLogStyle constructor.
17 * @param array $labelStyles
18 * @param array $messageStyles
20 public function __construct($labelStyles = [], $messageStyles = [])
22 parent::__construct($labelStyles, $messageStyles);
24 $this->labelStyles += [
25 RoboLogLevel::SIMULATED_ACTION => self::TASK_STYLE_SIMULATED,
27 $this->messageStyles += [
28 RoboLogLevel::SIMULATED_ACTION => '',
33 * Log style customization for Robo: replace the log level with
36 * @param string $level
37 * @param string $message
38 * @param array $context
42 protected function formatMessageByLevel($level, $message, $context)
45 if (array_key_exists('name', $context)) {
46 $label = $context['name'];
48 return $this->formatMessage($label, $message, $context, $this->labelStyles[$level], $this->messageStyles[$level]);
52 * Log style customization for Robo: add the time indicator to the
53 * end of the log message if it exists in the context.
55 * @param string $label
56 * @param string $message
57 * @param array $context
58 * @param string $taskNameStyle
59 * @param string $messageStyle
63 protected function formatMessage($label, $message, $context, $taskNameStyle, $messageStyle = '')
65 $message = parent::formatMessage($label, $message, $context, $taskNameStyle, $messageStyle);
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');