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.
In the version of Laravel 5.6 that I am using, the configuration file for logging is config/logging.php
There you will find the following section
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single'],
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'days' => 7,
],
...
]
Change the line
'channels' => ['single'],
into
'channels' => ['daily'],
Then it will be like:
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['daily'],
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'days' => 7,
],
...
]
It will create log files for each day in the format laravel-2018-08-13.log
in the logs directory.
The log directory will be like
Previously
After applying rotation configuration the directory is having the log file created for the current date (as circled one which is created for today 2018-08-13).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With