Answer the question
In order to leave comments, you need to log in
How to throw out logs from laravel, for example, to mail, telegrams?
I know how to send a letter to the mail or a message in a telegram, I have difficulties only in Laravel, when errors occur, write these errors into a variable and run your own method, which will send information about errors somewhere without affecting the built-in logging out of the box. I opened the logging documentation, tried a lot of things, but nothing helped.
Answer the question
In order to leave comments, you need to log in
app/Exceptions/Handler.php
class Handler extends ExceptionHandler
{
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
* @return void
*/
public function report(Exception $exception) {
if ($this->shouldReport($exception)) {
// Send report
}
}
In fact, everything is simple, if you read the documentation , you can find out about a cool class App\Exceptions\Handler
that handles exceptions, you need its method report
, which you can override and write your own logic.
An example of sending an email is even easy to google (the person even made his own package https://github.com/squareboat/sneaker ).
In short, here, and go ahead to create magic:
in config/logging.php
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single', 'telegram'],
'ignore_exceptions' => false,
],
'telegram' => [
'driver' => 'monolog',
'handler' => Monolog\Handler\TelegramBotHandler::class,
'with' => [
'apiKey' => env('TELEGRAM_BOT_TOKEN'),
'channel' => env('TELEGRAM_BOT_CHAT_ID'),
],
],
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question