Welcome Guest, Not a member yet? Register   Sign In
Error reporting hooks
#1

[eluser]Dave Blencowe[/eluser]
Hey,

Currently I am involved in developing a library with a friend and one of the functions relies on the library knowing when an error occurs in the application.

Is there a way or an existing hook so that I can execute a piece of code to either override CI writing to a log file or to execute a piece of code when this happens?

Thanks for any input you may have,
Dave Blencowe,
#2

[eluser]TheFuzzy0ne[/eluser]
I don't think so. The only way I can think of to prevent it writing to the log would be to actually override or extend the Log class, or whatever the class is that's writing to the log.
#3

[eluser]jtkendall[/eluser]
Hi Dave,

You can extend the CI_Exceptions class and either execute your code when the error is logged or when it's going to show the error on screen.

Code:
<?php

    class MY_Exceptions extends CI_Exceptions
    {

        public function __construct()
        {
            parent::__construct();
        }

        // or

        public function show_php_error($severity, $message, $filepath, $line)
        {
            // Your Code Here
        }

        public function log_exception($severity, $message, $filepath, $line)
        {
            // Your Code Here
        }

    }

Hope that helps.
#4

[eluser]Dam1an[/eluser]
The actual log_message function is system/codeigniter/common.php, so it's not really easy for a drop in replacement, as it involves modifying the core
It's possible to extend the Exception class which will catch errors, so they can be logged and then carry on as normal
#5

[eluser]Dave Blencowe[/eluser]
Well I think extending the exceptions class will be our best bet after discussion with my partner.
Your example is much appreciated JTkendall as I am not to sure on how extension of classes works fully.

Thanks for both your input,
Dave,




Theme © iAndrew 2016 - Forum software by © MyBB