예제 #1
0
 public static function __php_handleAssert($file, $line, $code, $desc = null)
 {
     \Cherry\debug("Assertion failed in %s on line %d", $file, $line);
     $log = DebugLog::getDebugLog();
     $str = sprintf("in %s on line %d", $file, $line);
     $bt = Debug::getBacktrace(1);
     self::showError($ca, 'Assertion failed', $str, $file, $line, $log, $bt);
     exit(1);
 }
 public function execute(IWebRequest $request, IWebResponse $response)
 {
     DebugLog::separator();
     DebugLog::log($request->postAll());
     $feeding = $this->feedingRepository->getInProgressOrNew();
     $this->executeInner($request, $response, $feeding);
     if ($request->post('docommit', false)) {
         $feeding->setStatus(Feeding::STATUS_Finalized);
         $this->model->setStatus($feeding->getStatus());
     }
     $this->feedingRepository->save($feeding);
     return $this->model;
 }
 public static function handleException(Exception $e)
 {
     switch (get_class($e)) {
         case 'RecordValidationException':
             return static::handleValidationError($e);
         default:
             $report = sprintf("<h1 style='color:red'>%s caught</h1>\n", get_class($e));
             $report .= sprintf("<h2>Details</h2>\n<pre>%s</pre>\n", print_r($e, true));
             $report .= sprintf("<h2>URI</h2>\n<p>%s</p>\n", htmlspecialchars($_SERVER['REQUEST_URI']));
             $report .= sprintf("<h2>_SERVER</h2>\n<pre>%s</pre>\n", print_r($_SERVER, true));
             if ($GLOBALS['Session']->Person) {
                 $report .= sprintf("<h2>User</h2>\n<pre>%s</pre>\n", print_r($GLOBALS['Session']->Person->getData(), true));
             }
             $report .= ErrorHandler::formatBacktrace(debug_backtrace());
             $report .= '<h2>Debug Log</h2><pre>' . print_r(DebugLog::getLog(), true) . '</pre>';
             if (Site::$debug) {
                 die($report);
             } else {
                 Email::send(Site::$webmasterEmail, 'Unhandeld ' . get_class($e) . ' on ' . $_SERVER['HTTP_HOST'], $report);
                 ErrorHandler::handleFailure('There was a problem... our technical staff has been notified. Please retry later.');
             }
     }
 }
예제 #4
0
파일: debug.php 프로젝트: noccy80/cherryphp
                fputs(STDOUT, $so . "\n");
            }
        }
    }
    static function openLog($logfile, $append = true)
    {
        self::$hlog = fopen($logfile, $append ? 'a+' : 'w+');
    }
    static function getDebugLog()
    {
        self::initqueue();
        return self::$fifo->popAll();
    }
}
if (getenv('DEBUG_LOGFILE')) {
    DebugLog::openLog(getenv('DEBUG_LOGFILE'), false);
}
function getLineInfo(array $btr)
{
    $cn = !empty($btr['class']) ? $btr['class'] : null;
    $ct = !empty($btr['type']) ? $btr['type'] : '··';
    $cm = !empty($btr['function']) ? $btr['function'] : null;
    /*
        $fn = (!empty($btr['file']))?$btr['file']:null;
        $fl = (!empty($btr['line']))?$btr['line']:'??';
        $fnp = explode(_DS_,$fn);
        if (count($fnp)>3) {
            $fnp = array_splice($fnp,-3);
            array_unshift($fnp,'...');
            $fn = join(_DS_,$fnp);
        }
예제 #5
0
 /**
  * Logger:: CreateLog
  * Used internally and externally to actually insert data into the db.
  *
  */
 public function createLog($debug, $type = 'LOG', $trace = false)
 {
     $log = new DebugLog();
     $log->Message = $type != 'DUMP' && sizeof($debug['Parameters']) == 1 && is_string($debug['Variable']) ? $debug['Variable'] : json_encode($debug);
     $log->RequestID = $this->RequestID;
     $log->REMOTE_ADDR = $_SERVER['REMOTE_ADDR'];
     $log->URI = $_SERVER['REQUEST_URI'];
     $log->POST = !empty($_POST) ? json_encode($_POST) : "";
     $log->GET = !empty($_GET) ? json_encode($_GET) : "";
     $log->Type = $type;
     $log->Time = now();
     if (!$trace) {
         $trace = debug_backtrace();
     }
     $curlog = sizeof($trace) > 2 ? $trace[2] : sizeof($trace) > 1 ? $trace[1] : $trace[0];
     if ($type == 'TRACE') {
         ob_start();
         debug_print_backtrace();
         $debug['Trace'] = nl2br(ob_get_clean());
         $log->Payload = json_encode($debug);
     }
     if ($type == 'DUMP') {
         $log->Payload = json_encode($debug);
     }
     $log->Function = @$curlog['function'];
     $log->Class = @$curlog['class'];
     $log->Line = @$curlog['line'];
     $log->File = @$curlog['file'];
     $log->Save();
 }
예제 #6
0
 protected static function handleError($query = '', $queryLog = false)
 {
     // save queryLog
     if ($queryLog) {
         $queryLog['error'] = static::$_mysqli->error;
         self::finishQueryLog($queryLog);
     }
     // get error message
     if ($query == 'connect') {
         $message = mysqli_connect_error();
     } elseif (static::$_mysqli->errno == 1062) {
         throw new DuplicateKeyException(static::$_mysqli->error);
     } else {
         $message = static::$_mysqli->error;
     }
     // respond
     $report = sprintf("<h1 style='color:red'>Database Error</h1>\n");
     $report .= sprintf("<h2>URI</h2>\n<p>%s</p>\n", htmlspecialchars($_SERVER['REQUEST_URI']));
     $report .= sprintf("<h2>Query</h2>\n<p>%s</p>\n", htmlspecialchars($query));
     $report .= sprintf("<h2>Reported</h2>\n<p>%s</p>\n", htmlspecialchars($message));
     $report .= ErrorHandler::formatBacktrace(debug_backtrace());
     if ($GLOBALS['Session']->Person) {
         $report .= sprintf("<h2>User</h2>\n<pre>%s</pre>\n", var_export($GLOBALS['Session']->Person->data, true));
     }
     if (self::$DebugMode) {
         print $report;
         DebugLog::dumpLog();
         exit;
     } else {
         Email::send(self::$AdministratorEmail, 'Database error on ' . $_SERVER['HTTP_HOST'], $report);
         ErrorHandler::handleFailure('Error while communicating with database', ErrorHandler::ERROR_DB);
     }
 }
 protected function insert(Feeding $feeding)
 {
     DebugLog::log('1');
     $feeding->setId($this->uuidHelper->get());
     DebugLog::log('2');
     DebugLog::log('3');
     $this->dbFactory->getConnection()->update("insert into feedings set\n\t\t\t\t  `id`=:id\n\t\t\t\t, `date_time`=:date_time\n\t\t\t\t, `status`=:status\n\t\t\t\t, `breast_left`=:breast_left\n\t\t\t\t, `breast_right`=:breast_right\n\t\t\t\t, `milking`=:milking\n\t\t\t\t, `pee`=:pee\n\t\t\t\t, `poo`=:poo\n\t\t\t\t, `bottle`=:bottle\n\t\t\t", array('id' => $feeding->getId(), 'date_time' => $feeding->getDateTime()->format('Y-m-d H:i:s'), 'status' => $feeding->getStatus(), 'breast_left' => $feeding->getBreastLeft(), 'breast_right' => $feeding->getBreastRight(), 'milking' => $feeding->getMilking(), 'pee' => $feeding->getPee(), 'poo' => $feeding->getPoo(), 'bottle' => $feeding->hasBottle() ? $feeding->getBottle()->encode() : null));
     DebugLog::log('4');
 }