Monday, August 8, 2016

Laravel Log files by date

Hello everyone

Today we will discuss about laravel logging system.

Laravel logging mechanism is pretty simple – it writes all the errors to a file at /storage/logs/laravel.log. It’s convenient until the file gets bigger. And then we have a problem to find a bug from yesterday or some days ago. How can we solve this?

When we want to see log in laravel then we SSH to our server, go to /storage/logs folder and run ls -l command for the files list with information. And see this:

-rw-rw-r-- 1 forge forge 31580639 Jul  4 07:52 laravel.log

From above log files, it is very difficult to find log for a specific day. But it is very easy to change from single log file to daily basis log file. it’s only one setting in config/app.php file:

    /*
    |--------------------------------------------------------------------------
    | Logging Configuration
    |--------------------------------------------------------------------------
    |
    | Here you may configure the log settings for your application. Out of
    | the box, Laravel uses the Monolog PHP logging library. This gives
    | you a variety of powerful log handlers / formatters to utilize.
    |
    | Available Settings: "single", "daily", "syslog", "errorlog"
    |
    */

    'log' => env('APP_LOG', 'single'),

As we can see, by default the value is single file, but we can change it to daily or others – either in the config file itself, or in environment file .env.

When we change the setting to daily, instead of one laravel.log – we will get separate file for each date – something like laravel-2016-08-07.log.

No comments:

Post a Comment