Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Logger.php

function Logger::format

1 call to Logger::format()
Logger::__construct in vendor/symfony/http-kernel/Log/Logger.php

File

vendor/symfony/http-kernel/Log/Logger.php, line 139

Class

Logger
Minimalist PSR-3 logger designed to write in stderr or any other stream.

Namespace

Symfony\Component\HttpKernel\Log

Code

private function format(string $level, string $message, array $context, bool $prefixDate = true) : string {
    if (str_contains($message, '{')) {
        $replacements = [];
        foreach ($context as $key => $val) {
            if (null === $val || \is_scalar($val) || $val instanceof \Stringable) {
                $replacements["{{$key}}"] = $val;
            }
            elseif ($val instanceof \DateTimeInterface) {
                $replacements["{{$key}}"] = $val->format(\DateTimeInterface::RFC3339);
            }
            elseif (\is_object($val)) {
                $replacements["{{$key}}"] = '[object ' . $val::class . ']';
            }
            else {
                $replacements["{{$key}}"] = '[' . \gettype($val) . ']';
            }
        }
        $message = strtr($message, $replacements);
    }
    $log = \sprintf('[%s] %s', $level, $message);
    if ($prefixDate) {
        $log = date(\DateTimeInterface::RFC3339) . ' ' . $log;
    }
    return $log;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal