I am using Tenancy for Laravel (Stancl/Tenancy), Laravel 11, package. Everything working well. I want to know how to supply name of channel as a variable to log messages in the tenant's folder using log channel.
As an example below
Log::channel('activity')->info('['.tenant('id')." ] [ ".Auth::user()->name.' ] displayed consumption form');
The above line writes using activity log channel and stores well as I have defined the 'activity' channel.
Just like that, I want to use variable name instead of the channel name 'activity' like tenant('id').
As a test case I created 'demo' channel in logging.php file as the function tenant('id') points to tenant name 'demo' as mentioned below
Log::channel(tenant('id'))->info('['.tenant('id')." ] for [ ".Auth::user()->name.' ] displayed consumption form')
;
The above does not create/write to the file in 'demo' directory meant for the tenant (of course, I have given correct path in the logging.php file. However, if I write 'demo' instead of tenant('id'), it works. Also, in every function if I declare as written below
$logChannel = tenant('id');
and use the $logChannel also works, but I am forced to use this declaration everywhere which I wish to avoid.
How to mention or whether we can supply variable name in the Log::channel($variable)->info();