Laravel How to create a custom Log file

On Laravel 5.8, you cannot use Log::useFiles() to create custom log files,after some digging around I found that I could add a channel to config/logging.php like this

1
2
3
4
5
'customlog' => [
'driver' => 'single',
'path' => storage_path('logs/custom.log'),
'level' => 'info',
],

and write to it like this

1
Log::channel('customlog')->info('Hello world!!');

IF you want to create a log file using date format, modify in config/logging.php like this

1
2
3
4
5
'customlog' => [
'driver' => 'daily',
'path' => storage_path('logs/custom.log'),
'level' => 'info',
],
坚持原创技术分享,您的支持将鼓励我继续创作!
0%