Welcome Guest, Not a member yet? Register   Sign In
Log maintenance library
#11

[eluser]ayukawaa[/eluser]
[quote author="Binod Kumar Luitel" date="1369797443"]Here is a little of my contribution to Codeigniter:
Code:
...
function __construct(){
  log_message('debug','Log_Maintenance : class loaded');
  parent::__construct($rules);
  
  $this->CI =& get_instance();
        // check whether the config is a numeric number before assigning
  if(isset($this->CI->config->item('logs_files_for')))
         $this->logs_files_for = (int) (is_numeric($this->CI->config->item('logs_files_for')) ? $this->CI->config->item('logs_files_for') : 15);
        // delete the old log files
  $this->delete_logs();
}
...
[/quote]


Good work, I'm using it now, just one thing that I have changed for myself:

In the function __construct() because you have the default setting (private $logs_files_for = 15;) no need for more, just a cast it with a string '0' before to get rid of nulls, NEGATIVE, etc... and done...

"-3" IS is_numeric AND int

use this
Code:
$new_logs_files_for = (int)('0'.$this->CI->config->item('logs_files_for'));
$this->logs_files_for = $new_logs_files_for>0 ? $new_logs_files_for : $this->logs_files_for;
or this
Code:
$new_logs_files_for = (int)('0'.$this->CI->config->item('logs_files_for'));
if($new_logs_files_for>0)
{
   $this->logs_files_for = $new_logs_files_for;
}

This way you don't have to check if config var exists, numeric, int, etc... and only changes value IF it is greater than 0.


Messages In This Thread
Log maintenance library - by El Forum - 06-22-2009, 05:42 PM
Log maintenance library - by El Forum - 06-23-2009, 02:55 AM
Log maintenance library - by El Forum - 07-16-2009, 09:13 PM
Log maintenance library - by El Forum - 08-07-2011, 09:17 AM
Log maintenance library - by El Forum - 08-07-2011, 08:12 PM
Log maintenance library - by El Forum - 08-09-2011, 01:07 AM
Log maintenance library - by El Forum - 08-09-2011, 02:58 AM
Log maintenance library - by El Forum - 05-28-2013, 08:17 PM
Log maintenance library - by El Forum - 07-17-2013, 11:38 PM
Log maintenance library - by El Forum - 07-24-2013, 12:57 AM
Log maintenance library - by El Forum - 08-30-2013, 01:48 AM



Theme © iAndrew 2016 - Forum software by © MyBB