Skip to content

Instantly share code, notes, and snippets.

@besingamkb
Created July 9, 2014 04:24
Show Gist options
  • Save besingamkb/ca4447cf3293068f2d2a to your computer and use it in GitHub Desktop.
Save besingamkb/ca4447cf3293068f2d2a to your computer and use it in GitHub Desktop.
saving logs in codeigniter
/*audit trail*/
private $logdir = "application/logs/";
private $logfile;
private $logs;
private function writeFile($logs) {
$fileOpen = fopen($this->logdir . $this->logfile, 'a+');
fwrite($fileOpen, $logs);
fclose($fileOpen);
}
protected function saveLogs($action = "null", $comment = "null") {
$datetime = time();
$this->logfile = "audittrail_" . date("mdY", $datetime) . ".csv";
$this->logs = $datetime . ',';
$this->logs .= $_SERVER['SERVER_ADDR'] . ',';
$this->logs .= self::ez_decrypt($this->session->userdata('user_id')) . ',';
$this->logs .= '"' . self::ez_decrypt($this->session->userdata('user_email')) . '",';
$this->logs .= '"' . $action .'",';
$this->logs .= '"' . $comment . '",';
$this->logs .= '"http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '"';
$this->writeFile("\r" . $this->logs);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment