Laravel - Logging - On Demand Channels
It is also possible to create an on-demand channel by providing the configuration at runtime without that configuration being present in your application's logging
configuration file. To accomplish this, you may pass a configuration array to the Log
facade's build
method:
use Illuminate\Support\Facades\Log;
Log::build([
'driver' => 'single',
'path' => storage_path('logs/custom.log'),
])->info('Something happened!');
You may also wish to include an on-demand channel in an on-demand logging stack. This can be achieved by including your on-demand channel instance in the array passed to the stack
method:
use Illuminate\Support\Facades\Log;
$channel = Log::build([
'driver' => 'single',
'path' => storage_path('logs/custom.log'),
]);
Log::stack(['slack', $channel])->info('Something happened!');