I have created a UniqueMessage
class which I want to use in log statements inside /Console/Kernel::schedule() to suppress repeated log messages.
I have tried to make an instance of my UniqueMessage
class in the constructor for Kernel
but it seems to me that the Kernel scheduler is run in a separate process for each run resulting in a new UniqueMessage
instance for each run. So then the suppressing does not work.
A workaround could be to instantiate my UniqueMessage
outside of Kernel
. But where should I do this?
Based on Best Ways To Define Global Variable In Laravel I assume I could create an instance in app/Providers/AppServiceProvider::boot(). The example here is using View Composers but I am not going to use the variables in views but in the Kernel class. So what is the best way to make an instance of my UniqueMessage
available (globally) for the Kernal instance (process)?
Tried:
use App\Services\UniqueMessage;
class Kernel extends ConsoleKernel
{
protected static $um;
/**
* Constructor
*/
public function __construct(Application $app, Dispatcher $events)
{
parent::__construct($app, $events);
$max=env('LOGACCS');
if (!isset(self::$um)) { self::$um=new UniqueMessage($max, ['Illuminate\Support\Facades\Log', 'info']); }
}
...
Expected:
Expected static $um to be truly static across each schedule run.