. * * ========================= * * This file contains the class PhpSystemLogger; * * @category API * @package DmarcSrg * @author Aleksey Andreev (liuch) * @license https://www.gnu.org/licenses/gpl-3.0.html GNU/GPLv3 */ namespace Liuch\DmarcSrg\Log; /** * Implements a logger to log messages via PHP's system logger, * using the OS's system logging mechanism or a file, depending on * what the error_log PHP configuration directive is set to. */ class PhpSystemLogger implements LoggerInterface { /** * System is unusable * * @param string $message * @param array $context * * @return void */ public function emergency($message, array $context = []): void { $this->log(LogLevel::EMERGENCY, $message, $context); } /** * Action must be taken immediately * * @param string $message * @param array $context * * @return void */ public function alert($message, array $context = []): void { $this->log(LogLevel::ALERT, $message, $context); } /** * Critical conditions * * @param string $message * @param array $context * * @return void */ public function critical($message, array $context = []): void { $this->log(LogLevel::CRITICAL, $message, $context); } /** * Runtime errors that do not require immediate action but should typically * be logged and monitored * * @param string $message * @param array $context * * @return void */ public function error($message, array $context = []): void { $this->log(LogLevel::ERROR, $message, $context); } /** * Exceptional occurrences that are not errors * * @param string $message * @param array $context * * @return void */ public function warning($message, array $context = []): void { $this->log(LogLevel::WARNING, $message, $context); } /** * Normal but significant events * * @param string $message * @param array $context * * @return void */ public function notice($message, array $context = []): void { $this->log(LogLevel::NOTICE, $message, $context); } /** * Interesting events * * @param string $message * @param array $context * * @return void */ public function info($message, array $context = []): void { $this->log(LogLevel::INFO, $message, $context); } /** * Detailed debug information * * @param string $message * @param array $context * * @return void */ public function debug($message, array $context = []): void { $this->log(LogLevel::DEBUG, $message, $context); } /** * Logs with an arbitrary level * * @param mixed $level * @param string $message * @param array $context * * @return void */ public function log($level, $message, array $context = []): void { switch ($level) { case LogLevel::EMERGENCY: case LogLevel::ALERT: case LogLevel::CRITICAL: case LogLevel::ERROR: case LogLevel::WARNING: case LogLevel::NOTICE: case LogLevel::INFO: case LogLevel::DEBUG: break; default: throw new \InvalidArgumentException('Invalid log level argument'); } \error_log("dmarc-srg [{$level}]: {$message}"); } }