public function log($message, $priority = self::INFO) { $context = ['at' => Helpers::getSource()]; if ($message instanceof Throwable) { $context['exception'] = $message; $message = ''; } $this->monolog->addRecord(self::PRIORITY_MAP[$priority] ?? Monolog\Logger::ERROR, $message, $context); }
/** * Renders blue screen. * @param \Exception * @return void */ public function render(\Exception $exception) { $panels = $this->panels; $info = array_filter($this->info); $source = Helpers::getSource(); $sourceIsUrl = preg_match('#^https?://#', $source); $title = $exception instanceof \ErrorException ? Helpers::errorTypeToString($exception->getSeverity()) : get_class($exception); $skipError = $sourceIsUrl && $exception instanceof \ErrorException && !empty($exception->skippable) ? $source . (strpos($source, '?') ? '&' : '?') . '_tracy_skip_error' : NULL; require __DIR__ . '/templates/bluescreen.phtml'; }
/** * @return string */ protected function formatLogLine($message, $exceptionFile = NULL) { return implode(' ', array(@date('[Y-m-d H-i-s]'), preg_replace('#\\s*\\r?\\n\\s*#', ' ', $this->formatMessage($message)), ' @ ' . Helpers::getSource(), $exceptionFile ? ' @@ ' . basename($exceptionFile) : NULL)); }
/** * Default mailer. * * @param $message * @param $email * @param string|\Exception|\Throwable * * @internal */ public function defaultMailer($message, $email, $exceptionFile = NULL, $priority = NULL) { if (!is_null($this->host)) { $host = $this->host; } else { $host = preg_replace('#[^\\w.-]+#', '', isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : php_uname('n')); } try { $emailSendJson = Nette\Utils\Json::decode(file_get_contents($this->directory . '/email-sent'), Nette\Utils\Json::FORCE_ARRAY); } catch (Nette\Utils\JsonException $e) { $emailSendJson = []; } $emailSendJson[$exceptionFile] = TRUE; @file_put_contents($this->directory . '/email-sent', Nette\Utils\Json::encode($emailSendJson)); $mail = new Nette\Mail\Message(); $mail->setFrom($this->fromEmail ?: (Nette\Utils\Validators::isEmail("noreply@{$host}") ? "noreply@{$host}" : "*****@*****.**"))->addTo(is_array($email) ? $email[0] : $email)->setSubject("PHP: An error (" . $this->getTitle($message, $priority) . ") occurred on the server {$host}")->setHtmlBody($this->formatMessage($message) . "\n\nsource: " . Tracy\Helpers::getSource() . (is_null($exceptionFile) ? '' : "\n\nexception link: " . Nette\Utils\Strings::replace($exceptionFile, ['~^(.*)exception--~' => 'http://' . $host . $this->path . 'exception--']))); if (is_array($email)) { foreach ($email as $k => $v) { if ($k == 0) { continue; } $mail->addCc($v); } } $this->mailerClass->send($mail); }
/** * Default mailer. * @param string * @param string * @return void * @internal */ public function defaultMailer($message, $email) { $host = preg_replace('#[^\\w.-]+#', '', isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : php_uname('n')); $parts = str_replace(array("\r\n", "\n"), array("\n", PHP_EOL), array('headers' => implode("\n", array("From: noreply@{$host}", 'X-Mailer: Tracy', 'Content-Type: text/plain; charset=UTF-8', 'Content-Transfer-Encoding: 8bit')) . "\n", 'subject' => "PHP: An error occurred on the server {$host}", 'body' => $this->formatMessage($message) . "\n\nsource: " . Helpers::getSource())); mail($email, $parts['subject'], $parts['body'], $parts['headers']); }