Error Log | Laravel - Errors and Logging
What is Errors and Logging in Laravel?
- When you start a new Laravel project, error and exception handling is already configured for you.
- The App\Exceptions\Handler class is where all exceptions triggered by your application are logged and then rendered back to the user.
- For logging, Laravel utilizes the Monolog library, which provides support for a variety of powerful log handlers.
- Laravel configures several of these handlers for you, allowing you to choose between a single log file, rotating log files, or writing error information to the system log.
Errors:
- Errors and exception handling is already configured for you when you start a new Laravel project.
- Normally, in a local environment we need to see errors for debugging purposes. We need to hide these errors from users in production environment.
- This can be achieved with the variable APP_DEBUG set in the environment file .env stored at the root of the application.
- For local environment, the value of APP_DEBUG should be true but for production it needs to be set to false to hide errors.
Note
- After changing the APP_DEBUG variable, restart the Laravel server.
Error Detail
- The amount of error detail your application displays through the browser is controlled by the app.debug configuration option in your config/app.php configuration file.
- By default, this configuration option is set to respect the APP_DEBUG environment variable, which is stored in your .env file.
- For local development, you should set the APP_DEBUG environment variable to true.
- In your production environment, this value should always be false.
Logging:
- Laravel provides a simple abstraction layer on top of the powerful Monolog library.
- By default, Laravel is configured to create a log file for your application
- in the storage/logs directory. You may write information to the logs using the Log facade:
- It is useful to improve the reliability of the system. Laravel supports different logging modes like single, daily, syslog, and errorlog modes.
- You can set these modes in config/app.php file.
- You can see the generated log entries in storage/logs/laravel.log file.
- The logger provides the eight logging levels defined in RFC 5424: emergency, alert, critical, error, warning, notice, info and debug.