Log level fix for Codeigniter

Log level fix for Codeigniter

When writing quality applications, logging is one of the most important thing we need to look for. Just like every other framework Codeigniter has the logging facility and it works fine.

But the order of log levels defined in codeigniter is wrong. Here is the default log levels in codeigniter.

  1. ERROR
  2. DEBUG
  3. INFO
  4. ALL

What is wrong here?

INFO level need to have more severity than DEBUG. And the order needs to be revised as follows

  1. ERROR
  2. INFO
  3. DEBUG
  4. ALL

Most of the popular log frameworks follow above standard and here is the Log4j Wiki about it’s Log Level.

Why is this wrong?

Someone might argue what is the problem here and argue that we treat it seperately. But the problem is not that.

  • Internally codeigniter does nearly ~10 DEBUG logs for a simple page request.
  • And inside my controllers I do DEBUG and INFO logs seperately
  • Normally we don’t need DEBUG logs in the production and just only need INFO logs
  • But the because of this strange log level order we can’t just only filter out INFO logs

The Fix - Core

I’ve worked on this and sent a pull request to Codeigniter Github repository and It is waiting for the approval.

Hope it will be added in the future versions of codeigniter

The Fix - Extending CI

I simply can’t just wait for the core fix approve for this and I extend the CI Log library and fix this. Here is the steps how it can be fixed

  • Save this file into your application/libraries folder
  • With MY_Log.php ( If you’ve changed Subclass Prefix to something else, use it instead MY_ )

Okay, this is my thoughts on this and If you’ve found this is interesting please find my pull request and express your opinion.