Logging and errors
The application log, the error page, and requests to other services
Application log
Fegg\Log writes one line per entry to htdocs/_fegg/site/data/log/fegg-YYYY-MM-DD.log. Call it from anywhere (controllers, your classes in site/src/):
use Fegg\Log;
Log::error('Import failed for {file}', array('file' => $name, 'exception' => $e));
See Log for the line format, the levels, the settings (log_level, log_retention_days, FEGG_LOG_DIR) and the methods.
Uncaught errors
An exception or error that no code catches (a Fegg\Database\QueryException, a missing template, a PHP error ...) ends the request with HTTP 500:
- It is written to the PHP error log and to the application log, with the stack trace and, for errors raised by a template, the
.tplfile and line (Template: news/detail.tpl:12). - In developer mode the details are shown in the browser.
- Everyone else gets the error page
core/template/error/500.html. What a half-rendered page already printed is discarded.
To use your own design, put a file at htdocs/_fegg/site/template/error/500.html. It is plain HTML, not a template (no {{ }} tags, no includes), so it still works when the templates or the database are what broke. Inline its CSS or link to files of a site folder (/_fegg/site/template/main/css/...).
Catch an exception only when the page can do something useful with it; otherwise let it reach the 500 page and the log. When you catch \Throwable, rethrow Fegg\Http\Halt (see Ending a response).
Requests to other services
Call other services (an API, a webhook) with Fegg\Http\Client, which has timeouts. Catch its Fegg\Http\ClientException, log it and show the page without that part: see HTTP client.