سلام
من این کلاس لاگ و برای خودم نوشتم شاید به درد شما هم بخوره
یک فولدر به اسم mylogs داخل فولدر application بساز
class Logfile {
private $actions;
private $dbtable;
private $db;
private $ci;
private $file;
private $filename;
private $logdir;
private $fh;
public function __construct($config_new = false){
//instantiate CI
$this->ci = &get_instance();
//default options
$this->actions = array(
'login','upload','download','modif_perms','mkdir', 'mkfile','rmdir','rmfile',
'copyfile','movefile','adduser','edituser','rmuser ','addrole','editrole','rmrole',
'editsettings','addcompany','editcompany','rmcompa ny','adddepartament','editdepartament',
'rmdepartament','activatecompany','deactivatecompa ny','view'
);
$this->dbtable = 'logs';
$this->db = false;
$this->file = true;
$this->filename = date('Y-m-d').'.log';
$this->logdir = APPPATH.'mylogs/';
//setting options
if ($config_new) foreach ($config_new as $key=>$value) {
if ($value != '')
$this->{$key} = $value;
}
if ($this->file) {
if (!is_dir($this->logdir)) {
@mkdir($this->logdir.'/',0644);
}
$this->fh = fopen($this->logdir.$this->filename,'a');
}
}
public function message($action, $params, $message = false) {
$agent = 'browser-'.$this->ci->agent->browser().
',browser version-'.$this->ci->agent->version().
',robot-'.$this->ci->agent->robot().
',mobile-'.$this->ci->agent->mobile().
',platform-'.$this->ci->agent->platform().
',referrer-'.$this->ci->agent->referrer().
',ip-'.$this->ci->input->ip_address();
$mesaj = 'username:'.$this->ci->session->userdata('username')
.'->action:'.$action
.'->message:'.$message
.'->date:'.date('Y-m-d H:i:s')
.'->detail:'.$agent
;
if ($this->file) {
fwrite($this->fh, $mesaj. "\r\n");
}
return false;
}
}