Laravel log – single file or files by date?

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 you have a problem to find a bug from yesterday or some days ago. How can you solve this?

Basically, the real problem looks like this: you SSH to your 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

True story from one of my projects – laravel.log file is 31 MB. It’s pretty difficult to find anything there, if a client reports that “unknown bug” happened to him a few days ago.

Luckily, it’s really easy to change – 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 you can see, by default the value is single file, but you can change it to daily (or others, leaving that for you to explore) – either in the config file itself, or in environment file .env.

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

Like our articles?
Check out our Laravel online courses!

7 COMMENTS

  1. Keep in mind that by default – if I’m not mistaken – only 5 days of log files are retained.

    If you want more, you can add a ‘log_max_files configuration’ value in the app config.

  2. Hi, I did the same thing to use it with arcanedev/log-viewer.
    but the log files are not being created. I’m using 5.4…
    please help.

  3. We can create log file daily, but the problem is “Permission” to the file. Is it possible to give 777 permission to log file for the dynamically created log file?

LEAVE A REPLY

Please enter your comment!
Please enter your name here