[eluser]Unknown[/eluser]
Hi all,
I just tweaked the logging code so that I could log to an arbitrary files.
I know its not wise to change the core code but this was too minor to write a separate
Log library or extend the core Log library.
I am posting the code hoping it might be useful for someone.
----------- Code Changes --------------
system/codeigniter/Common.php line 241
Add $filepath to the function definition
Code:
function log_message($level = 'error', $message, $php_error = FALSE, [b]$filepath[/b])
{
static $LOG;
$config =& get_config();
if ($config['log_threshold'] == 0)
{
return;
}
$LOG =& load_class('Log');
$LOG->write_log($level, $message, $php_error, [b]$filepath[/b]);
}
system/libraries/Log.php line 75
Add $filepath to the function definition
Code:
function write_log($level = 'error', $msg, $php_error = FALSE, [b]$filepath[/b])
inside this function on line 98
replace this code with
Code:
$filepath = $this->log_path.'log-'.date('Y-m-d').EXT;
$message = '';
with
Code:
if(empty($filepath))
$filepath = $this->log_path.'log-'.date('Y-m-d').EXT;
else
$filepath = $this->log_path. $filepath .'-'.date('Y-m-d').EXT;
$message = '';
------- Usage ---------
Normally we use
log_message('error', " msg to log ") ;
You can optionally use now
log_message('error', " msg to log", '', 'app' ) ;
The later will be logged to some file like app-2009-12-31.php the log directory.
---------------
Derek, It would be great if you can accomodate this small modification in the coming releases.
regds,
Shikhar