mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
1b8d295767
API CHANGE: Debug::showError(), Debug::showLines(), Debug::log(), and Debug::header() removed NEW: Logging provided ZendLog has been removed and monolog introduced instead as a dependency. The “ErrorLogger” injection point is now the used as the logger that errors are fed into, and implements PSR-3’s Psr\Log\LoggerInterface. The SS_ERROR_LOG setting expect a Monolog Logger to be provided as the ErrorLogger.
91 lines
2.2 KiB
PHP
91 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\Framework\Logging;
|
|
|
|
use Monolog\Logger;
|
|
use Monolog\Handler\AbstractProcessingHandler;
|
|
use Monolog\Formatter\FormatterInterface;
|
|
|
|
/**
|
|
* Produce a friendly error message
|
|
*/
|
|
class DebugViewFriendlyErrorFormatter implements FormatterInterface
|
|
{
|
|
|
|
protected $statusCode = 500;
|
|
protected $friendlyErrorMessage = 'Error';
|
|
protected $friendlyErrorDetail;
|
|
|
|
public function getStatusCode() {
|
|
return $this->statusCode;
|
|
}
|
|
|
|
public function setStatusCode($statusCode) {
|
|
$this->statusCode = $statusCode;
|
|
}
|
|
|
|
public function getTitle($title) {
|
|
return $this->friendlyErrorMessage;
|
|
}
|
|
|
|
public function setTitle($title) {
|
|
$this->friendlyErrorMessage = $title;
|
|
}
|
|
|
|
public function getBody($title) {
|
|
return $this->friendlyErrorDetail;
|
|
}
|
|
|
|
public function setBody($body) {
|
|
$this->friendlyErrorDetail = $body;
|
|
}
|
|
|
|
public function format(array $record)
|
|
{
|
|
|
|
return $this->output();
|
|
}
|
|
|
|
public function formatBatch(array $records) {
|
|
return $this->output();
|
|
}
|
|
|
|
public function output() {
|
|
// TODO: Refactor into a content-type option
|
|
if(\Director::is_ajax()) {
|
|
return $this->friendlyErrorMessage;
|
|
|
|
} else {
|
|
// TODO: Refactor this into CMS
|
|
if(class_exists('ErrorPage')){
|
|
$errorFilePath = \ErrorPage::get_filepath_for_errorcode(
|
|
$this->statusCode,
|
|
class_exists('Translatable') ? \Translatable::get_current_locale() : null
|
|
);
|
|
|
|
if(file_exists($errorFilePath)) {
|
|
$content = file_get_contents($errorFilePath);
|
|
if(!headers_sent()) {
|
|
header('Content-Type: text/html');
|
|
}
|
|
// $BaseURL is left dynamic in error-###.html, so that multi-domain sites don't get broken
|
|
return str_replace('$BaseURL', \Director::absoluteBaseURL(), $content);
|
|
}
|
|
}
|
|
|
|
|
|
$renderer = \Debug::create_debug_view();
|
|
$output = $renderer->renderHeader();
|
|
$output .= $renderer->renderInfo("Website Error", $this->friendlyErrorMessage, $this->friendlyErrorDetail);
|
|
|
|
if(\Email::config()->admin_email) {
|
|
$mailto = \Email::obfuscate(\Email::config()->admin_email);
|
|
$output .= $renderer->renderParagraph('Contact an administrator: ' . $mailto . '');
|
|
}
|
|
|
|
$output .= $renderer->renderFooter();
|
|
return $output;
|
|
}
|
|
}
|
|
}
|