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 o开发者_如何学Pythonption in user manual nor any solution in Google.
Is there any 3rd party logging library available for CI?
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.
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)
{
//...
}
}
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
if you are fine with changing core log file it can easy by following below goto main/core/log.php and then replce
$filepath = $this->_log_path.'log-'.date('Y-m-d').'.'.$this->_file_ext;
$filepath = $this->_log_path.'log-'.date('Y-m-d').'.'.$this->_file_ext;
if($level == 'ERROR'){
$filepath = $this->_log_path.'error-'.date('Y-m-d').'.'.$this->_file_ext;
}
精彩评论