- Log Storage

When you start a new Laravel project, error and exception handling is already configured. The App\Exceptions\Handler class is where all exceptions triggered by your application are logged and then rendered back to the user.

The debug option in config/app.php file determines how much information about an error is displayed to the user. This option is set to respect the value of the APP_DEBUG variable, which is stored in .env file.
- For local development, you should set the APP_DEBUG environment variable to true. In production environment, this value should be false.

For logging, Laravel utilizes the Monolog library. The log files are created in the storage/logs directory.

HTTP Exceptions - Custom HTTP Error Pages

To generate HTTP error codes like 404, 500, etc. anywhere in Laravel application, you can use the abort() method.
- Optionally, you may provide a custom response text:
abort(403, 'Unauthorized action.');

Custom HTTP Error Pages

Laravel makes it very easy to use custom error pages for each separate error codes. Just create an errors folder in resources/views/ directory, then crete a "Code_Error.blade.php" file for each HTTP Error you want to customize. Laravel framework will automatically detect the file in "views/errors/" folder and use it when that error occurs.
- Here is an example for http error code 404.

1. Create a view at resources/views/errors/404.blade.php, and copy the following code in that file:
<!doctype html>
<html lang="{{app()->getLocale()}}">
<meta charset="utf-8">
<title>Error 404</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
body {
margin:1px 1%;
<h1>Error 404 - Page not exists</h1>
<h2>Which does not exist cannot affect you.</h2>
<h3>If you want something that exists, your-self is the Truth in this present.</h3>
2. Access an address of a page that not exist, for example:
- It will display the content from the resources/views/errors/404.blade.php file.

Same way you can design error pages for http error codes 401, 403, 500.

Log Storage

Laravel supports writing log information to single files, daily files, the syslog, and the errorlog.
To configure which storage mechanism Laravel uses, modify the log option in config/app.php file.
- For example, to use daily log files instead of a single file, set the log value in app.php file to 'daily':
'log'=> 'daily'

Maximum Daily Log Files

When using the daily log mode, Laravel will retain five days of log files. To adjust the number of retained files, you may add a log_max_files value to your config/app.php file:
'log_max_files'=> 7

Log Levels

In Laravel you can use the following severity levels - from least severe to most severe: debug, info, notice, warning, error, critical, alert, emergency.
Laravel writes all log levels to storage. If you wish to configure a minimum severity that should be logged, change the value of the APP_LOG_LEVEL in ".env" file:
Or the log_level option in "config/app.php" file.
'log_level'=> 'error'
Laravel will log all levels greater than or equal to the specified severity. For example, if you set the value error, it will log: error, critical, alert, emergency messages.

Writing information to the logs

You may write information to the logs using the Log facade.
namespace App\Http\Controllers;

use App\User;
use Illuminate\Support\Facades\Log;
use App\Http\Controllers\Controller;

class UserController extends Controller{
  //Show the profile for the given user
  //@param  int  $id
  //@return view
  public function showProfile($id){
    Log::info('Showing user profile for user: '.$id);

    return view('user.profile', ['user'=> User::findOrFail($id)]);
- The log class provides the eight logging levels:
- An array of data may also be passed to the Log methods. This data will be formatted and displayed with the log message:
Log::notice('User failed to login.', ['id'=> $user->id]);

- Documentation: Laravel - Errors and Logging

Daily Test with Code Example

Which tag adds a new line into a paragraph?
<b> <br> <p>
First line ...<br>
Other line...
Which CSS property can be used to add space between letters?
text-size word-spacing letter-spacing
#id {
  letter-spacing: 2px;
What JavaScript function can be used to get access to HTML element with a specified ID?
getElementById() getElementsByTagName() createElement()
var elm = document.getElementById("theID");
var content = elm.innerHTML;
Click on the "echo" correct instruction.
echo "CoursesWeb.net" echo "CoursesWeb.net"; echo ""CoursesWeb.net";
echo "Address URL: http://CoursesWeb.net";
HTTP Errors and Logging

Last accessed pages

  1. SHA1 Encrypt data in JavaScript (8134)
  2. Read Excel file data in PHP - PhpExcelReader (56751)
  3. Insert, Select and Update NULL value in MySQL (26535)
  4. jQuery Drag and Drop Rows between two similar Tables (6882)
  5. Ajax-PHP Chat Script (36546)

Popular pages this month

  1. Read Excel file data in PHP - PhpExcelReader (488)
  2. PhpSpreadsheet - Read, Write Excel and LibreOffice Calc files (388)
  3. Register and show online users and visitors (365)
  4. Courses Web: PHP-MySQL JavaScript Ajax HTML CSS Flash-AS3 (346)
  5. Insert, Select and Update NULL value in MySQL (237)