phplaravellogginglaravel-5

Laravel log file based on date


By default laravel saves the log file to a single log file called laravel.log located in /storage/logs/laravel.log

my question is how can i get a new log file everyday and store the log files like /storage/logs/laravel-2016-02-23.log for the current date, so i need everyday a new log file saved to /storage/logs/

i think we can do that by extending the default Illuminate\Foundation\Bootstrap\ConfigureLogging bootstraper class but i'm not sure how i can do that

i would really appreciate it if anyone could help me.

Thanks in advance.


Solution

  • It's actually a lot simpler than that. In your config/app.php you'll see the line:

    'log' => 'single',
    

    closer to the bottom of the file. Laravel by default uses the single method, which stores all errors in a single, expanding file. If you change this line to:

    'log' => 'daily',
    

    it will tell Laravel that you'd prefer to have multiple logs, each suffixed with the date of the when the error occurs.

    There's a few other methods available, so be sure to check out the official documentation for more info.


    This answer is for Laravel 5.2, which is the version specified in the original question. In never versions of Laravel, the Logging config has been moved to it's own config file, as seen by @ShanthaKumara's answer (https://stackoverflow.com/a/51816907/3965631). Please do not suggest edits to change this answer to reflect the new version.