CodeIgniter Forums
How to make email notifications for errors and exceptions? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: How to make email notifications for errors and exceptions? (/showthread.php?tid=86527)

Pages: 1 2


How to make email notifications for errors and exceptions? - krotovroman - 01-30-2023

How to make email notifications for errors and exceptions without changing the file /system/Debug/Exceptions.php?
I want to change error handling without changing engine code!


RE: How to make email notifications for errors and exceptions? - superior - 01-30-2023

Isn't this possible in `App\Config\Exceptions` or are you looking for a different solution?


RE: How to make email notifications for errors and exceptions? - kenjis - 01-30-2023

You can't now.
You need to replace Exceptions.


RE: How to make email notifications for errors and exceptions? - krotovroman - 01-31-2023

(01-30-2023, 06:36 PM)kenjis Wrote: You can't now.
You need to replace Exceptions.
That is, without files in the system folder, is this impossible?

(01-30-2023, 05:51 AM)superior Wrote: Isn't this possible in `App\Config\Exceptions` or are you looking for a different solution?

Can you write a sample code how can i do it without editing folder @"system"? Please!


RE: How to make email notifications for errors and exceptions? - kenjis - 01-31-2023

See https://codeigniter4.github.io/CodeIgniter4/extending/core_classes.html


RE: How to make email notifications for errors and exceptions? - alex777 - 02-17-2023

I monitor /writable/logs folder for files every 15 min. If there is error file - script send me motification via telegram or email.


RE: How to make email notifications for errors and exceptions? - krotovroman - 02-19-2023

I try it, but this is not work. What is wrong?

[Image: LEWuPY.jpg]
PHP Code:
<?php
namespace App\Libraries;

use 
CodeIgniter\API\ResponseTrait;
use 
CodeIgniter\Exceptions\PageNotFoundException;
use 
CodeIgniter\HTTP\CLIRequest;
use 
CodeIgniter\HTTP\Exceptions\HTTPException;
use 
CodeIgniter\HTTP\IncomingRequest;
use 
CodeIgniter\HTTP\Response;
use 
Config\Exceptions as ExceptionsConfig;
use 
Config\Paths;
use 
ErrorException;
use 
Psr\Log\LogLevel;
use 
Throwable;

/**
* Exceptions manager
*/
class Exceptions extends Exceptions
{
    /**
    * Gathers the variables that will be made available to the view.
    */
    protected function collectVars(Throwable $exceptionint $statusCode): array
    {
        $trace $exception->getTrace();

        if ($this->config->sensitiveDataInTrace !== []) {
            $this->maskSensitiveData($trace$this->config->sensitiveDataInTrace);
        }

        $return = [
            'title'  => get_class($exception),
            'type'    => get_class($exception),
            'code'    => $statusCode,
            'message' => $exception->getMessage(),
            'file'    => $exception->getFile(),
            'line'    => $exception->getLine(),
            'trace'  => $trace,
        ];
        
        
//send email
        mail('[email protected]''test');

        return $return;
    



RE: How to make email notifications for errors and exceptions? - kenjis - 02-19-2023

I think "class Exceptions extends Exceptions" does not work.
It seems fatal error.

And the collectVars() method works only in development mode.


RE: How to make email notifications for errors and exceptions? - krotovroman - 02-20-2023

(01-31-2023, 05:14 PM)kenjis Wrote: See https://codeigniter4.github.io/CodeIgniter4/extending/core_classes.html

(02-19-2023, 07:18 PM)kenjis Wrote: I think "class Exceptions extends Exceptions" does not work.
It seems fatal error.

And the collectVars() method works only in development mode.

yes I use now development mode.
how to fix it to work?


RE: How to make email notifications for errors and exceptions? - kenjis - 02-23-2023

Exceptions::exceptionHandler() is the exception handler.
Override the method.