Laravel Errors And Log


Laravel Errors And Log – Laravel provides the some default error and logging system when we start a new project. In addition laravel also provides you monolog library which enables provides various powerful log handlers. Here in this tutorial we are going to cover the laravel error logging system with various example.


Laravel Errors And Log | Create Custom Log File Example

Configuration

  • Error Detail – You can set the error detail configuration in config/app.php file. Go to the line ‘debug’ => env(‘APP_DEBUG’, true) and set it to true if you want to keep the system in debug mode.
  • Log Modes – Laravel supports various types of log modes –
    1. Single – Store logs in single file.
    2. Daily – Create New file daily to store logs.
    3. Syslog – System log.
    You can find the log settings in config/app.php file. By default it is set single.

    'log' => 'single'

    .
    You can change it to daily or syslog also.

Laravel Monolog Configuration-

You can configura Monolog configuration in config/app.php Add the monolog configuration before returning the $app variable.

Laravel Enable Error Logging –

To Enable the error log add the below settings in the config/app.php file-

Laravel enable debug mode Configuration

//'debug' => env('APP_DEBUG', false) Default 
'debug' => env('APP_DEBUG', true)

Laravel Create Custom Logs –

You can crate Custom log in Laravel Simply as Below –

Laravel Create Custom Log File:

<?php
class TestController extends Controller
{
    
    public function editProfile($id)
    {
        Log::info('Editing profile. Userid = '.$id);
		// Other stuffs Here..
    }
}

?>

The above example will create a log with the information provided.

Here are the following logging levels available-

  • Emergency
    Log::emergency($error);
  • Alert
    Log::alert($error);
  • Critical
    Log::critical($error);
  • Error
    Log::error($error);
  • Warning
    Log::warning($error);
  • Notice
    Log::notice($error);
  • Infor
    Log::info($error);
  • Debug
    Log::debug($error);

Advertisements

Add Comment

📖 Read More