Example #1
0
 /**
  * Logs the passed Exception. This includes a mail and error info file if it is enabled in 
  * the app.ini. A log entry is also sent to log4php. If logging failed this method must throw 
  * any exceptions. Exceptions must be registered in the 
  * {@link ExceptionHandler::$pendingLogExceptions} property.
  * 
  * @param \Throwable $e
  */
 private function log(\Throwable $e)
 {
     if ($e instanceof StatusException && (!$this->logStatusExceptionsEnabled || in_array($e->getStatus(), $this->logExcludedHttpStatus))) {
         return;
     }
     $simpleMessage = $this->createSimpleLogMessage($e);
     error_log($simpleMessage, 0);
     if (isset($this->logDetailDirPath) || isset($this->logMailRecipient)) {
         $detailMessage = $this->createDetailLogMessage($e);
         if (isset($this->logMailRecipient)) {
             // @todo validate email
             $subject = 'An ' . get_class($e) . ' occurred';
             $header = 'From: ' . $this->logMailAddresser . "\r\n" . 'Reply-To: ' . $this->logMailAddresser . "\r\n" . 'X-Mailer: PHP/' . phpversion();
             @mail($this->logMailRecipient, $subject, $detailMessage, $header);
         }
         if (isset($this->logDetailDirPath)) {
             $defLogBasePath = $this->logDetailDirPath . DIRECTORY_SEPARATOR . date('Y-m-d_His') . str_replace('\\', '_', get_class($e));
             $ext = '';
             for ($i = 0; is_file($defLogBasePath . $ext . self::LOG_FILE_EXTENSION); $i++) {
                 $ext = '_' . $i;
             }
             $defLogPath = $defLogBasePath . $ext . self::LOG_FILE_EXTENSION;
             try {
                 IoUtils::putContents($defLogPath, $detailMessage);
                 IoUtils::chmod($defLogPath, $this->logDetailFilePerm);
             } catch (\Exception $e) {
                 $logE = $this->createLoggingFailedException($e);
                 $this->pendingLogException[spl_object_hash($logE)] = $logE;
             }
         }
     }
     // cannot log deprecated exception because class loader cant be called anymore if
     // "Deprecated: Call-time pass-by-reference has been deprecated"-Warning occoures.
     if (isset($this->logger) && $this->stable) {
         try {
             $this->logger->error($simpleMessage, $e);
         } catch (\Exception $e) {
             $logE = $this->createLoggingFailedException($e);
             $this->pendingLogException[spl_object_hash($logE)] = $logE;
         }
     }
 }