Configuring Errors & Logging in Laravel 5

Sharad Jaiswal
Sharad Jaiswal

Posted On: Sep 12, 2018

Configuring Errors & Logging in Laravel 5

 

An Introduction Errors & Logging in Laravel 5

In software/ web development Error logging plays a vital role in the maintenance and debugging process of application or project. It is believed that at the time of development if you add error logging/ tracing capabilities in your project then in future if any bugs or errors will occur or produced then it will reduce the time of fixing those bugs. Logging helps you to quickly traces bugs and evaluate the health of the application in development or maintenance period.

Laravel comes with excellent error and exception handling feature. When you install Laravel framework (MVC) error and exception handling is configured at the same time.

Laravel App\Exceptions\Handler class is responsible for handling all exceptions triggered by your application and logs them or display them to app users.

For logging error, Laravel imitates Monolog (the error logging library).

Monolog is an error Logging library for PHP that provides support for a variety of powerful log handlers. Monolog allow you to send logs to files on disk, sockets, inboxes/mails, databases and various web services.Many of these log handlers are automatically configured by Laravel. Laravel allow you to choose a single or rotating log files or writing error information directly to the system log.

Configuring Error Detail in Laravel: How much error information is displayed or showed to End Users

Laravel provides an easy way for configuring Errors, the debug option of config/app.php (Laravel's configuration file) handles the what information about an error is actually displayed to the users. By default, debug option is set with respect to the value of the APP_DEBUG environment variable, which is stored in your .env file (.env file is available in root directory Laravel's project).

For local (development), you should set the APP_DEBUG environment variable to true, so if any errors are occurred or generated at development time then you can get detailed information about that error. In the production environment, this value must always be false, otherwise, you have a risk of exposing sensitive configuration values/information to your application's end users that will be a security threat.

Configuring Log Storage in Laravel: Managing how, where and at what frequency logs are saved.

Laravel supports multiple options to write log information. You can write your log information to single files, daily files, the Syslog, and the error logs.In order to configure Laravel's storage mechanism,modify log option of config/app (Laravel's configuration file).By default it set to single file, if you wish to change this from single to daily log files, you should set the log value in your app configuration file i.e config/app.php to daily by changing "single" to "daily"

'log' => 'daily'

Configuring Log Severity Levels in Laravel.

In Laravel ,you can manage Log Severity Levels by adding log_level option in config/app.php in Laravel's configuration file. Once you have configured log_level option , Laravel will start logging all levels greater than or equal to the specified severity of log. For example, a default log_level of error will log error or critical or alert or emergency messages.

'log_level' => env('APP_LOG_LEVEL', 'error'),

    Please Login or Register to leave a response.

    Related Articles

    Laravel Tutorials

    Laravel 5.5 Middleware complete Tutorial

    In Laravel, you can think middleware as a system or tool that are used to filter all HTTP requests entering your application. Middleware works between request and response of our application. It sits ..

    Laravel Tutorials

    Laravel Pagination Ajax

    Creating Ajax based pagination is Laravel 5.6. Ajax (Asynchronous JavaScript and XML) is a technique to update a specific part of webpage asynchronously without reloading the page. In this article, we..

    Laravel Tutorials

    Laravel Pagination

    According to Wikipedia Pagination is a process of separating or dividing a document or digital contents into discrete pages. In Core PHP and other frameworks, paginating record is a painful task. Lara..

    Ask a Question