Welcome Guest, Not a member yet? Register   Sign In
Codeigniter error logging similar to PHP/Apache general error logging
#1

[eluser]sabya[/eluser]
I have to do error_reporting(0) in my production server. This causes PHP's normal error log not to log anything.

I have set "log_threshold" = 1 in the config.php.

But the format that CI logs the errors are different.

It will best, if I can get the normal PHP error logging.
I want the errors to be logged in the same format as it does in normal PHP/Apache installation.

That is: -
1. in the apache error_log
2. if there is an HTTP referrer present, log that.
3. no date based file separation. Log everything in a single file.
#2

[eluser]louis w[/eluser]
You could extend the CI_Log class and customize the output.
#3

[eluser]sabya[/eluser]
But I really don't want to write a logging handler myself. I just want to use the PHP's default handler.
#4

[eluser]louis w[/eluser]
CI's logged uses a propitiatory (more novice friendly) output for their logs. If you want something else it's going to require customization.
#5

[eluser]Chad Fulton[/eluser]
There are two solutions I see:

1. Disable CodeIgniter error handling system. I suspect that's not what you really want, however, since you're probably just interested in the log files. However, if you do want this, then you should comment out line 59 in system/codeigniter/CodeIgniter.php:
Code:
//set_error_handler('_exception_handler');
That would of course remove ALL of CodeIgniter's error handling. This is the solution that requires least customization, however.


2. Secondly, I suggest that rather than customizing CI_Log, you should customize CI_Exception class. In particular, you could override the log_exception function so that it called the native PHP function error_log, which would write to the apache error log as you want:

Code:
class MY_Exceptions extends CI_Exceptions {

    function log_exception($severity, $message, $filepath, $line) {

        $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];

        error_log(sprintf("PHP %s:  %s in %s on line %d", $severity, $message, $filepath, $line));

        parent::log_exception($severity, $message, $filepath, $line);

    }

}

That will do what you want, by mimicking the PHP error logging format, and logging the error using the native PHP function.
#6

[eluser]sabya[/eluser]
If I am logging through CodeIgniter's logger, I am missing this kind of error: -
Code:
[Fri Jul 31 04:25:26 2009] [error] [client 192.168.1.33] PHP Fatal error:  Maximum execution time of 3 seconds exceeded in F:\\Test\\system\\application\\controllers\\test.php on line 24

How can I get these error messages also?
#7

[eluser]thePiet[/eluser]
[quote author="sabya" date="1248370209"]I have to do error_reporting(0) in my production server.[/quote]

Why?




Theme © iAndrew 2016 - Forum software by © MyBB