protected function stderr($string) { if (Console::streamSupportsAnsiColors(\STDOUT)) { $string = Console::ansiFormat(" Error: " . $string, [Console::FG_RED]); } return fwrite(\STDERR, $string); }
/** * @inheritdoc */ public function init() { parent::init(); $this->stderrIsNotStdout = fstat(\STDERR)['dev'] != fstat(\STDOUT)['dev']; $this->stderrSupportsColors = Console::streamSupportsAnsiColors(\STDERR); $this->stdoutSupportsColors = Console::streamSupportsAnsiColors(\STDOUT); }
/** * Colorizes a message for console output. * @param string $message the message to colorize. * @param array $format the message format. * @return string the colorized message. * @see Console::ansiFormat() for details on how to specify the message format. */ protected function formatMessage($message, $format = [Console::FG_RED, Console::BOLD]) { $stream = PHP_SAPI === 'cli' ? \STDERR : \STDOUT; // try controller first to allow check for --color switch if (Yii::$app->controller instanceof \yii\console\Controller && Yii::$app->controller->isColorEnabled($stream) || Yii::$app instanceof \yii\console\Application && Console::streamSupportsAnsiColors($stream)) { $message = Console::ansiFormat($message, $format); } return $message; }
public function stdout($string) { if (Console::streamSupportsAnsiColors(STDOUT)) { $args = func_get_args(); array_shift($args); $string = Console::ansiFormat($string, $args); } return Console::stdout($string); }
public function init() { $this->_stdoutIsTerminal = posix_isatty(\STDOUT); if ($this->_stdoutIsTerminal) { $this->logVars = []; } $this->_stdoutSupportsAnsiColors = Console::streamSupportsAnsiColors(\STDOUT); $this->_stderrIsTerminal = posix_isatty(\STDERR); $this->_stderrSupportsAnsiColors = Console::streamSupportsAnsiColors(\STDERR); $this->_levelAnsiColorMap = [Logger::LEVEL_ERROR => $this->errorAnsiColor, Logger::LEVEL_WARNING => $this->warningAnsiColor, Logger::LEVEL_INFO => $this->infoAnsiColor, Logger::LEVEL_TRACE => $this->traceAnsiColor, Logger::LEVEL_PROFILE => $this->profileAnsiColor, Logger::LEVEL_PROFILE_BEGIN => $this->profileBeginAnsiColor, Logger::LEVEL_PROFILE_END => $this->profileEndAnsiColor]; parent::init(); }
/** * Returns a value indicating whether ANSI color is enabled. * * ANSI color is enabled only if [[color]] is set true or is not set * and the terminal supports ANSI color. * * @param resource $stream the stream to check. * @return boolean Whether to enable ANSI style in output. */ public function isColorEnabled($stream = \STDOUT) { return $this->color === null ? Console::streamSupportsAnsiColors($stream) : $this->color; }
/** * Prints a string to STDOUT * @param string $string */ public function stdout($string) { if (Yii::$app->request->isConsoleRequest) { if (Console::streamSupportsAnsiColors(STDOUT)) { $args = func_get_args(); array_shift($args); $string = Console::ansiFormat($string, $args); } Console::stdout($string . "\n"); } }
/** * @param $message * * @return string */ private function generateLabel($message) { $label = ''; //Add date to log if (true == $this->displayDate) { $label .= '[' . date($this->dateFormat, time()) . ']'; } //Add category to label if (true == $this->displayCategory) { $label .= "[" . $message[2] . "]"; } $level = Logger::getLevelName($message[1]); $tmpLevel = "[{$level}]"; if (Console::streamSupportsAnsiColors(\STDOUT)) { if (isset($this->color[$level])) { $tmpLevel = Console::ansiFormat($tmpLevel, [$this->color[$level]]); } else { $tmpLevel = Console::ansiFormat($tmpLevel, [Console::BOLD]); } } $label .= $tmpLevel; return $label; }
/** * Returns a value indicating whether ANSI color is enabled. * * ANSI color is enabled only if [[color]] is set true or is not set * and the terminal supports ANSI color. * * @param resource $stream the stream to check. * @return boolean Whether to enable ANSI style in output. */ private function _isColorEnabled($stream = \STDOUT) { return $this->controller->color === null ? Console::streamSupportsAnsiColors($stream) : $this->controller->color; }