By default detailed error reporting is turned on so it is helpful to see detailed error information which can be useful for debugging and troubleshooting issues. When this feature is turned off, when there is a problem in a page, a friendly error message will be displayed.
When development has ended, it is advised that you switch off debug mode, open the configuration file config/app.php
and change the debug
value to false.
/*
|--------------------------------------------------------------------------
| Application Debug Mode
|--------------------------------------------------------------------------
|
| When your application is in debug mode, detailed error messages with
| stack traces will be shown on every error that occurs within your
| application. If disabled, a simple generic error page is shown.
|
*/
'debug' => false,
When any exception is thrown, such as a SystemException
it will be recorded in the event log, however the ApplicationException
will not be recorded.
<?php
throw new SystemException('I will be logged in the event log');
throw new ApplicationException('I will cause an error but won't be logged anywhere');
There are two ways the event log can be accessed:
- The event log can be viewed via the Administration area by navigating to System > Logs > Event Log.
- Alternatively it can be viewed in the file system by opening the file
storage/logs/system.log
.
During development you may wish to write to the Event log without throwing an exception, this is possible with the global traceLog()
helper.
<?php
// Write a string value
$val = 'Hello world';
traceLog('The value is '.$val);
// Dump an array value
$val = ['Some', 'array', 'data'];
traceLog($val);
// Trace an exception
try {
// [...]
}
catch (Exception $ex) {
traceLog($ex);
}
If you want to explore the variables available on a page, or inspect the contents of a specific variable, it is possible using the Twig dump()
function.
<body>
<!-- This will display all available variables -->
{{ dump() }}
<!-- This will display the object properties of {{ foo }} -->
{{ dump(foo) }}
</body>
By default any errors will be shown with a detailed error page containing the file contents, line number and stack trace where the error occurred. You can display a custom error page by setting the configuration value debug
to false in the app/config/app.php
script and creating a page with the URL /error
.