Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging into a two different log file types in Codeigniter

Is it possible in CI (natively) to log into two different files from two different controllers? I haven't found such option in user manual nor any solution in Google.

Is there any 3rd party logging library available for CI?

like image 572
Łukasz Koniecki Avatar asked Dec 01 '09 13:12

Łukasz Koniecki


3 Answers

I was looking for the same but couldn't find anything. I tweaked the code and it works fine. I have posted the same to CI forum http://forum.codeigniter.com/thread-25933.html

Have a look it probably will serve your purpose.

like image 103
shikhar Avatar answered Oct 19 '22 21:10

shikhar


You can override the Log library with your own log class, specially override function write_log($level = 'error', $msg, $php_error = FALSE). You can see the original Log library code in the file system/libraries/Log.php. To create your own Log library, overriding default behaviour, read this page.

Create the file system/application/libraries/MY_Log.php:

class MY_Log extends CI_Log {

  function MY_Log()
  {
    parent::CI_Log();
  }
  //your code
  //...
  function write_log($level = 'error', $msg, $php_error = FALSE)
  {
  //...
  }
}
like image 42
Donny Kurnia Avatar answered Oct 19 '22 22:10

Donny Kurnia


Is it possible in CI (natively) to log into two different files from two different controllers?

No, it isn't. Log file names are pretty much hard coded. See system/libraries/Log.php

Is there any 3rd party logging library available for CI?

That I don't know, but assuming you come empty-handed from Google, I would either ask on the CodeIgniter forums, create your own logging library, or extend the existing one. Instructions

like image 27
MiseryIndex Avatar answered Oct 19 '22 20:10

MiseryIndex