I had this worked very simple way:
I ran into the same problem on Laravel 5.6
In config/logging.php
I just updated daily channel's path value with php_sapi_name()
in it.
This creates seperate durectory for different php_sapi_name and puts log file with the time stamp into their perticular directory.
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/' . php_sapi_name() . '/laravel.log'),
'level' => 'debug',
'days' => 7,
]
So for me,
- Log files are created under
fpm-fcgi
directory: Logs from website, owner: www-data
- Log files are created under
cli
directory: from the artisan command(cronjob). owner: root
More info on Laravel 5.6 logging: https://laravel.com/docs/5.6/logging
Here is my config/logging.php
file:
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Log Channel
|--------------------------------------------------------------------------
|
| This option defines the default log channel that gets used when writing
| messages to the logs. The name specified in this option should match
| one of the channels defined in the "channels" configuration array.
|
*/
'default' => env('LOG_CHANNEL', 'stack'),
/*
|--------------------------------------------------------------------------
| Log Channels
|--------------------------------------------------------------------------
|
| Here you may configure the log channels 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 Drivers: "single", "daily", "slack", "syslog",
| "errorlog", "custom", "stack"
|
*/
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['daily'],
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/' . php_sapi_name() . '/laravel.log'),
'level' => 'debug',
'days' => 7,
],
'slack' => [
'driver' => 'slack',
'url' => env('LOG_SLACK_WEBHOOK_URL'),
'username' => 'Laravel Log',
'level' => 'critical',
],
'syslog' => [
'driver' => 'syslog',
'level' => 'debug',
],
'errorlog' => [
'driver' => 'errorlog',
'level' => 'debug',
],
],
];
cron
job totouch
a new log file at midnight every day (under the correct user, of course). – Cottonyphp artisan
as the user that you want to create the log file. – Cottonysudo crontab -u www-data -e
– Engenia