<?php

declare(strict_types=1);

namespace FecaMailshots\Support;

final class ErrorLogLogger implements Logger
{
    public function info(string $message, array $context = []): void
    {
        error_log($this->format('INFO', $message, $context));
    }

    public function error(string $message, array $context = []): void
    {
        error_log($this->format('ERROR', $message, $context));
    }

    /** @param array<string, mixed> $context */
    private function format(string $level, string $message, array $context): string
    {
        $payload = $context === [] ? '' : ' ' . json_encode($context, JSON_UNESCAPED_SLASHES);
        return sprintf('[feca-mailshots][%s] %s%s', $level, $message, $payload);
    }
}
