HEX
Server: Apache/2.4.34 (Red Hat) OpenSSL/1.0.2k-fips
System: Linux WORDPRESS 3.10.0-1160.118.1.el7.x86_64 #1 SMP Thu Apr 4 03:33:23 EDT 2024 x86_64
User: digital (1020)
PHP: 7.2.24
Disabled: NONE
Upload Files
File: /datos/www/fabricas.colombiatrade.com.co/vendor2/consolidation/robo/src/Log/RoboLogStyle.php
<?php
namespace Robo\Log;

use Robo\Common\TimeKeeper;
use Consolidation\Log\LogOutputStyler;

/**
 * Robo Log Styler.
 */
class RoboLogStyle extends LogOutputStyler
{
    const TASK_STYLE_SIMULATED = 'options=reverse;bold';

    /**
     * RoboLogStyle constructor.
     *
     * @param array $labelStyles
     * @param array $messageStyles
     */
    public function __construct($labelStyles = [], $messageStyles = [])
    {
        parent::__construct($labelStyles, $messageStyles);

        $this->labelStyles += [
            RoboLogLevel::SIMULATED_ACTION => self::TASK_STYLE_SIMULATED,
        ];
        $this->messageStyles += [
            RoboLogLevel::SIMULATED_ACTION => '',
        ];
    }

    /**
     * Log style customization for Robo: replace the log level with
     * the task name.
     *
     * @param string $level
     * @param string $message
     * @param array $context
     *
     * @return string
     */
    protected function formatMessageByLevel($level, $message, $context)
    {
        $label = $level;
        if (array_key_exists('name', $context)) {
            $label = $context['name'];
        }
        return $this->formatMessage($label, $message, $context, $this->labelStyles[$level], $this->messageStyles[$level]);
    }

    /**
     * Log style customization for Robo: add the time indicator to the
     * end of the log message if it exists in the context.
     *
     * @param string $label
     * @param string $message
     * @param array $context
     * @param string $taskNameStyle
     * @param string $messageStyle
     *
     * @return string
     */
    protected function formatMessage($label, $message, $context, $taskNameStyle, $messageStyle = '')
    {
        $message = parent::formatMessage($label, $message, $context, $taskNameStyle, $messageStyle);

        if (array_key_exists('time', $context) && !empty($context['time']) && array_key_exists('timer-label', $context)) {
            $duration = TimeKeeper::formatDuration($context['time']);
            $message .= ' ' . $context['timer-label'] . ' ' . $this->wrapFormatString($duration, 'fg=yellow');
        }

        return $message;
    }
}