dimanche 29 novembre 2020

Trigger action(s) before Exception print to the log file - Laravel

I monitor my local Laravel logs by doing this :

tail -f storage/logs/laravel.log | grep .ERROR:

enter image description here

[2020-11-29 08:46:01] local.ERROR: SQLSTATE[HY000] [2002] Connection refused (SQL: select `color_code`, `name` from `skills` order by `created_at` desc) {"exception":"[object] (Illuminate\\Database\\QueryException(code: 2002): SQLSTATE[HY000] [2002] Connection refused (SQL: select `color_code`, `name` from `skills` order by `created_at` desc) at /Users/hunter/Sites/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:671) 

Rather than keep monitoring it, I would like to add an action (do something) right before it printed into the Log file.

Ex.

  • Send me an email
  • Store into logs table
  • do something before log printed in log file

I've tried

/Users/hunter/Sites/app/app/Exceptions/Handler.php



public function report(Throwable $exception)
{

    Log::debug('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>RUNNING ');
    parent::report($exception);
}

Result: I don't see my log printed.

How would one go above and do this ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire