Laravel: How to write a LOG into a separate file?

PHP

I want to create a new logfile in Laravel and write some information into. I dont want to use the default logfile because I dont want to mix my new log entries with the system entries. 

Something like this:

Log::info('mylogfile.txt', 'Something happened!'); 
Software Question created: 2020-05-17 08:51 CodeReacher

3

In Laravel >= 5.6 you can use Log Channels. In this way you can create log channels which can be handled as unique log files with drivers, paths and log levels. Edit your config file and add a new channel:

config/logging.php:

return [
    'channels' => [ 
        'myLogChannel' => [
            'driver' => 'single',
            'path' => storage_path('logs/seperate.log'),
            'level' => 'debug',
        ],
    ],
];

Now you can use this new driver in this way:

Log::channel('myLogChannel')->info('It works!'); 
answered 2020-05-17 09:01 Igniter