HAWK_TOKEN, ]); } /** * Gets singleton instance * Obtém instância singleton * * @return Logger Instance of Logger / Instância do Logger */ public static function getInstance(): Logger { if (self::$instance === null) { self::$instance = new self(); } return self::$instance; } /** * Logs an error with context * Registra um erro com contexto * * @param string $message Error message / Mensagem de erro * @param array $context Additional context data / Dados adicionais de contexto * @param string $type Error type/category / Tipo/categoria do erro */ public function error(string $message, array $context = [], string $type = 'WARNING'): void { // Log to Hawk // Registra no Hawk try { Catcher::get()->sendException(new Exception($message), [ 'type' => $type, 'context' => $context ]); } catch (Exception $e) { // If Hawk fails, we already have file logging as backup // Se o Hawk falhar, já temos o log em arquivo como backup error_log("Failed to send error to Hawk / Falha ao enviar erro para o Hawk: " . $e->getMessage()); } } /** * Logs a URL-specific error * Registra um erro específico de URL * * @param string $url The URL that generated the error / A URL que gerou o erro * @param string $error_group Error group/category / Grupo/categoria do erro * @param string $message_error Additional error details / Detalhes adicionais do erro * @param string $type Error type/category / Tipo/categoria do erro */ public function log(string $url, string $error_group, string $message_error = '', string $type = 'WARNING'): void { // If no Hawk token is configured, don't generate log // Se não houver token do Hawk configurado, não gera log if (empty(HAWK_TOKEN)) { return; } $this->error($error_group, [ 'url' => $url, 'timestamp' => time(), 'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? 'Unknown', 'message_error' => $message_error ], $type); } }