CodeIgniter Forums

Full Version: [INFO] Log errors to PHP error log
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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.
They are both really good ideas, and would be extremely useful, especially with ajax debugging.
(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