Kraken\Log\LoggerFactory::createFormatter PHP Метод

createFormatter() публичный Метод

Create one of Monolog formatters by specyfing it name of full class.
public createFormatter ( string $classOrName, mixed[] $args = [] ) : Kraken\Log\Formatter\FormatterInterface
$classOrName string
$args mixed[]
Результат Kraken\Log\Formatter\FormatterInterface
    public function createFormatter($classOrName, $args = [])
    {
        $classes = [$classOrName, '\\Monolog\\Formatter\\' . $classOrName];
        foreach ($classes as $class) {
            if (class_exists($class)) {
                $object = (new ReflectionClass($class))->newInstanceArgs($args);
                return new Formatter($object);
            }
        }
        throw new InvalidArgumentException("Monolog formatter [{$classOrName}] does not exist.");
    }

Usage Example

Пример #1
0
 /**
  * @param ConfigInterface $config
  * @param string $level
  * @param int $loggerLevel
  * @return HandlerInterface
  */
 private function createHandler(ConfigInterface $config, $level, $loggerLevel)
 {
     $factory = new LoggerFactory();
     $formatter = $factory->createFormatter('LineFormatter', [$config->get('log.config.messagePattern'), $config->get('log.config.datePattern'), true]);
     $filePermission = $config->get('log.config.filePermission');
     $fileLocking = (bool) $config->get('log.config.fileLocking');
     $filePath = $config->get('log.config.filePattern');
     $loggerHandler = $factory->createHandler('StreamHandler', [$this->filePath($filePath, $level), $loggerLevel, false, $filePermission, $fileLocking]);
     $loggerHandler->setFormatter($formatter);
     return $loggerHandler;
 }
All Usage Examples Of Kraken\Log\LoggerFactory::createFormatter