Welcome Guest, Not a member yet? Register   Sign In
Small improvement to write_log
#1

[eluser]Unknown[/eluser]
The log_message function only accepts a string value as a message. This means that the string value will be concatenated even if the log message will not be written to the file, for example because logging is turned of or has a high threshold. Right? And, concatenation is a a more or less expensive operation. Right?

Now I am not a performance expert, nor am I very experienced with CodeIgniter.

Would the addition of the following lines be a performance improvement? The lines would go in Log.php file in the write_log function of the log class.


Code:
if(is_array($msg))
{
   $msg = implode('', $msg);
}

$message .= $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --> '.$msg."\n";

The last line in the above code is the existing line (for reference to understand where I would place the if statement.)

The above code would allow to give the log_message function an array, which would be concatenated only just before it is used to compile the message and thus after it is made sure the message is going to be written.




Theme © iAndrew 2016 - Forum software by © MyBB