<?php
namespace Api\Core\Log;

use Monolog\Logger;
use Monolog\Handler\SyslogHandler;
use Monolog\Processor\UidProcessor;
use Monolog\Formatter\JsonFormatter;

class LoggerFactory {
    public static function create(?string $name): Logger {
        $ident = $name ?? 'api';
        $logger = new Logger($ident);
        $handler = new SyslogHandler($ident, LOG_USER);
        $handler->setFormatter(new JsonFormatter());
        $logger->pushHandler($handler);
        $logger->pushProcessor(new UidProcessor());
        return $logger;
    }
}
