Example #1
0
File: Helper.php Project: rj28/test
 public static function logException(Exception $e, $mail = true)
 {
     $di = DI::getDefault();
     if ($di->has('request')) {
         /** @var \Phalcon\Http\Request $request */
         $request = $di->getShared('request');
         $requestUri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '<!undefined>';
         //$queryString = isset($_SERVER['QUERY_STRING']) ? ($_SERVER['QUERY_STRING'] ? '?' . $_SERVER['QUERY_STRING'] : '') : '?<!undefined>';
         $message = date('Y-m-d H:i:s') . ' ' . get_class($e) . ': ' . $e->getMessage() . "\n" . 'UserAgent: ' . $request->getUserAgent() . "\n" . 'HTTP Referrer: ' . urldecode($request->getHTTPReferer()) . "\n" . $request->getClientAddress() . " URL: " . $request->getScheme() . '://' . $request->getHttpHost() . urldecode($requestUri) . "\n" . $e->getTraceAsString() . "\n";
     } else {
         $message = date('Y-m-d H:i:s') . ' ' . $e->getMessage() . "\n" . "There is no request object\n" . $e->getTraceAsString();
     }
     if (Config::instance()->mail_exceptions && $mail) {
         switch (true) {
             //			case $e instanceof PageNotFound:
             //			case $e instanceof Phalcon\Mvc\Dispatcher\Exception:
             case $e instanceof DoNotMail:
                 break;
             default:
                 \MailQueue::push2admin('Exception', $message);
                 break;
         }
     }
     \Logger::messages()->error($message);
 }
Example #2
0
function logException(Exception $e, $mail = true)
{
    Logger::messages()->exception($e);
    if (Config::instance()->production) {
        if (Phalcon\DI::getDefault()->has('request')) {
            /** @var \Phalcon\Http\Request $request */
            $request = Phalcon\DI::getDefault()->getShared('request');
            $message = sprintf("%s %s: %s\n" . "UserAgent: %s\n" . "HTTP Referer: %s\n" . "%s URL: %s://%s\n" . "LoggedUser: %s\n" . "%s", date('Y-m-d H:i:s'), get_class($e), $e->getMessage(), $request->getUserAgent(), urldecode($request->getHTTPReferer()), $request->getClientAddress(), $request->getScheme(), $request->getHttpHost() . urldecode(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '<!undefined>'), $e->getTraceAsString());
        } else {
            $message = date('Y-m-d H:i:s') . ' ' . $e->getMessage() . "\n" . "There is no request object\n" . $e->getTraceAsString();
        }
        switch (true) {
            //			case $e instanceof PageNotFound:
            //			case $e instanceof Phalcon\Mvc\Dispatcher\Exception:
            //				break;
            default:
                if (Config::instance()->mail_exceptions && $mail) {
                    MailQueue::push2admin('Exception', $message);
                }
                break;
        }
    } else {
        throw $e;
    }
}