log_file = $log_path; if ($this->log_file != '') { if (file_exists($this->log_file) && is_writable($this->log_file)) { $this->active = true; } } } /** * Prepare array name/value pairs for logging. * * @param array $info value pairs to prepare * @return string resulting values */ private function prepare_array($info) { $wr = ""; foreach ($info as $name => $value) { $wr.= $name.": ".$value."\r\n"; } return $wr; } /** * Truncates log file to zero lenght deleting all data inside. */ public function truncate() { $f = fopen($this->log_file, "w+"); fclose($f); } /** * Writes log info name/value into the file withou heading. * * @param mixed $object object to dump * @param string $mode file open mode */ public function slog($info, $mode = "a+") { if ($this->active) { $f = fopen($this->log_file, $mode); fwrite ($f, "$info"); fwrite ($f, "\r\n"); fclose($f); } } /** * Writes log info name/value into the file. * * @param string $msg log entry message * @param mixed $object object to dump * @param string $mode file open mode */ public function log($msg, $info, $mode = "a+") { if ($this->active) { $info = $this->prepare_array($info); $f = fopen($this->log_file, $mode); fwrite ($f, sprintf("[%s] : %s\r\n", date('Y-m-d h:i:s'), $msg)); fwrite ($f, "$info"); fwrite ($f, "\r\n"); fclose($f); } } /** * Writes object dump into the log file withou heading. * * @param mixed $object object to dump * @param string $mode file open mode */ public function sdump($object, $mode = "a+") { if ($this->active) { $obj = print_r($object, true); $f = fopen($this->log_file, $mode); fwrite ($f, "$obj"); fwrite ($f, "\r\n"); fclose($f); } } /** * Writes a object dump into the log file. * * @param string $msg log entry message * @param mixed $object object to dump * @param string $block adds start or end dump limiters { none | start | end } * @param string $mode file open mode */ public function dump($msg, $object, $block = "none", $mode = "a+") { if ($this->active) { $obj = print_r($object, true); $f = fopen($this->log_file, $mode); if ($block == "start") fwrite ($f, "-- DUMP BLOCK STARTED ---------------------------------- \r\n"); fwrite ($f, sprintf("[%s] : %s\r\n", date('Y-m-d h:i:s'), $msg)); fwrite ($f, "$obj"); fwrite ($f, "\r\n"); if ($block == "end") fwrite ($f, "-------------------------------------------------------- \r\n"); fclose($f); } } } } ?>