0 follower

Final Class Yiisoft\Log\Message\Formatter

InheritanceYiisoft\Log\Message\Formatter

Formatter formats log messages.

Public Methods

Hide inherited methods

Method Description Defined By
format() Formats a log message for display as a string. Yiisoft\Log\Message\Formatter
setFormat() Sets the format for the string representation of the log message. Yiisoft\Log\Message\Formatter
setPrefix() Sets a PHP callable that returns a string to be prefixed to every exported message. Yiisoft\Log\Message\Formatter
setTimestampFormat() Sets a date format for the log timestamp. Yiisoft\Log\Message\Formatter

Method Details

Hide inherited methods

format() public method

Formats a log message for display as a string.

public string format ( Yiisoft\Log\Message $message, array $commonContext )
$message Yiisoft\Log\Message

The log message to be formatted.

$commonContext array

The user parameters in the key => value format.

return string

The formatted log message.

throws RuntimeException

for a callable "format" that does not return a string.

                public function format(Message $message, array $commonContext): string
{
    if ($this->format === null) {
        return $this->defaultFormat($message, $commonContext);
    }
    $formatted = ($this->format)($message, $commonContext);
    if (!is_string($formatted)) {
        throw new RuntimeException(sprintf(
            'The PHP callable "format" must return a string, %s received.',
            get_debug_type($formatted)
        ));
    }
    return $this->getPrefix($message, $commonContext) . $formatted;
}

            
setFormat() public method

Sets the format for the string representation of the log message.

See also \Yiisoft\Log\Message\Formatter::$format.

public void setFormat ( callable $format )
$format callable

The PHP callable to get a string representation of the log message.

                public function setFormat(callable $format): void
{
    $this->format = $format;
}

            
setPrefix() public method

Sets a PHP callable that returns a string to be prefixed to every exported message.

See also \Yiisoft\Log\Message\Formatter::$prefix.

public void setPrefix ( callable $prefix )
$prefix callable

The PHP callable to get a string prefix of the log message.

                public function setPrefix(callable $prefix): void
{
    $this->prefix = $prefix;
}

            
setTimestampFormat() public method

Sets a date format for the log timestamp.

See also \Yiisoft\Log\Message\Formatter::$timestampFormat.

public void setTimestampFormat ( string $timestampFormat )
$timestampFormat string

The date format for the log timestamp.

                public function setTimestampFormat(string $timestampFormat): void
{
    $this->timestampFormat = $timestampFormat;
}