diff --git a/src/Admin/Server.php b/src/Admin/Server.php index b1ea2d4f6..69b844ba3 100644 --- a/src/Admin/Server.php +++ b/src/Admin/Server.php @@ -41,12 +41,12 @@ class Server extends AbstractServer event(new ConfigureMiddleware($pipe, $path, $this)); $pipe->pipe($path, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.admin.routes')])); - $pipe->pipe($path, new HandleErrors($errorDir, $app->inDebugMode())); + $pipe->pipe($path, new HandleErrors($errorDir, $app->make('log'), $app->inDebugMode())); } else { $app->register('Flarum\Update\UpdateServiceProvider'); $pipe->pipe($path, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.update.routes')])); - $pipe->pipe($path, new HandleErrors($errorDir, true)); + $pipe->pipe($path, new HandleErrors($errorDir, $app->make('log'), true)); } } diff --git a/src/Forum/Server.php b/src/Forum/Server.php index 0ab34b6be..ab56e6372 100644 --- a/src/Forum/Server.php +++ b/src/Forum/Server.php @@ -35,7 +35,7 @@ class Server extends AbstractServer $pipe->pipe($path, $app->make('Flarum\Http\Middleware\StartSession')); $pipe->pipe($path, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.install.routes')])); - $pipe->pipe($path, new HandleErrors($errorDir, true)); + $pipe->pipe($path, new HandleErrors($errorDir, $app->make('log'), true)); } elseif ($app->isUpToDate() && ! $app->isDownForMaintenance()) { $pipe->pipe($path, $app->make('Flarum\Http\Middleware\ParseJsonBody')); $pipe->pipe($path, $app->make('Flarum\Http\Middleware\StartSession')); @@ -46,7 +46,7 @@ class Server extends AbstractServer event(new ConfigureMiddleware($pipe, $path, $this)); $pipe->pipe($path, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.forum.routes')])); - $pipe->pipe($path, new HandleErrors($errorDir, $app->inDebugMode())); + $pipe->pipe($path, new HandleErrors($errorDir, $app->make('log'), $app->inDebugMode())); } else { $pipe->pipe($path, function () use ($errorDir) { return new HtmlResponse(file_get_contents($errorDir.'/503.html', 503)); diff --git a/src/Http/Middleware/HandleErrors.php b/src/Http/Middleware/HandleErrors.php index a30018dee..42b8d3155 100644 --- a/src/Http/Middleware/HandleErrors.php +++ b/src/Http/Middleware/HandleErrors.php @@ -13,6 +13,7 @@ namespace Flarum\Http\Middleware; use Franzl\Middleware\Whoops\ErrorMiddleware as WhoopsMiddleware; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; +use Psr\Log\LoggerInterface; use Zend\Diactoros\Response\HtmlResponse; use Zend\Stratigility\ErrorMiddlewareInterface; @@ -23,6 +24,11 @@ class HandleErrors implements ErrorMiddlewareInterface */ protected $templateDir; + /** + * @var LoggerInterface + */ + protected $logger; + /** * @var bool */ @@ -30,11 +36,13 @@ class HandleErrors implements ErrorMiddlewareInterface /** * @param string $templateDir + * @param LoggerInterface $logger * @param bool $debug */ - public function __construct($templateDir, $debug = false) + public function __construct($templateDir, LoggerInterface $logger, $debug = false) { $this->templateDir = $templateDir; + $this->logger = $logger; $this->debug = $debug; } @@ -58,6 +66,9 @@ class HandleErrors implements ErrorMiddlewareInterface return $whoops($error, $request, $response, $out); } + // Log the exception (with trace) + $this->logger->debug($error); + $errorPage = $this->getErrorPage($status); return new HtmlResponse($errorPage, $status);