Welcome Guest, Not a member yet? Register   Sign In
[INFO] Log errors to PHP error log
#1

I was looking for a possibility to log all CI errors into ordinary PHP log file (domain related in my case). But there was no such, i could just enable CI error logger, but that was not what i wanted, because of log analyzing and cleanup tasks. I wanted definitely get them as PHP errors.

So, that small piece of code do the magic. Create it as MY_Log.php under application/core/
PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
MY_Log extends CI_Log {

 
 public function write_log($level$msg) {
 
   if($level == 'error') {
 
     error_log($msg);
 
   }
 
   return parent::write_log($level$msg);
 
 }


So, that's it. It will log all errors as PHP errors in your PHP log file. Hope you like it! Blush
Reply
#2

Logging the PHP errors is one thing, but there is other information that is extremely useful for debugging. In my custom error handler I include a var dump of $_POST, $_COOKIE, the full URI, etc. As long as you're logging errors, the logs might as well be as useful as possible.
Reply
#3

They are both really good ideas, and would be extremely useful, especially with ajax debugging.
Reply
#4

(This post was last modified: 06-20-2016, 01:46 PM by V I R U S.)

(06-20-2016, 09:00 AM)skunkbad Wrote: Logging the PHP errors is one thing, but there is other information that is extremely useful for debugging. In my custom error handler I include a var dump of $_POST, $_COOKIE, the full URI, etc. As long as you're logging errors, the logs might as well be as useful as possible.

For sure you can extend it to what ever you want. That was just a small example. Big Grin
Reply




Theme © iAndrew 2016 - Forum software by © MyBB