registry[LogLevel::EMERGENCY] = []; $this->registry[LogLevel::ALERT] = []; $this->registry[LogLevel::CRITICAL] = []; $this->registry[LogLevel::ERROR] = []; $this->registry[LogLevel::WARNING] = []; $this->registry[LogLevel::NOTICE] = []; $this->registry[LogLevel::INFO] = []; $this->registry[LogLevel::DEBUG] = []; } /** * Logs with an arbitrary level. * * @param mixed $level * @param string $message * @param array $context * * @return void * @throws common_exception_InconsistentData */ public function log($level, $message, array $context = []) { if (! array_key_exists($level, $this->registry)) { $level = LogLevel::ERROR; } $this->registry[$level][] = [ 'message' => $message, 'context' => $context ]; } /** * Return all log entries for an arbitrary level * * @param string $level * @return array * @throws common_exception_InconsistentData */ public function get($level) { if (isset($this->registry[$level])) { return $this->registry[$level]; } else { throw new common_exception_InconsistentData('Unknown level ' . $level); } } /** * Check that a specific message has been logged at an arbitrary level * * @param $level * @param $message * @return bool * @throws common_exception_InconsistentData */ public function has($level, $message) { if (isset($this->registry[$level]) && count($this->registry[$level]) > 0) { foreach ($this->registry[$level] as $logEntry) { if ($logEntry['message'] == $message) { return true; } } return false; } else { throw new common_exception_InconsistentData('Unknown level ' . $level); } } }