<? /*############################################# logger class version 0.1 some parts of this file are from Ricardo Costa - ricardo.community@globo.com - 2002 from his logger class to be found at phpclasses.org - thanks #############################################*/ class Logger { var $path; var $filename; /* constructor expects: STRING logfile name, STRING logfile_rotation returns: VOID */ function Logger($path,$logfile_name,$logfile_rotation) { $this->path = $path; $extension = ($logfile_name == "")?"unnamed":$logfile_name; if ($logfile_rotation == "DAILY") $this->filename = date("Y.m.d")."_".$extension.".log"; elseif ($logfile_rotation == "MONTHLY") $this->filename = date("Y.m")."_".$extension.".log"; else $this->filename = $extension.".log"; } /* public method to add a log entry to logfile expects: STRING message returns: VOID */ function addLog($message) { $this->_log($message); } /* private method to write data to logfile expects: STRING message returns: VOID throws: FILE ERROR */ function _log($message, $type) { $logger_file = fopen($this->path.$this->filename,"a"); if(!$logger_file) die("error while trying to write logdata to file. Check permissions"); // $ini = strlen($GLOBALS["REQUEST_URI"]) - 40; $content = $this->_buildMessage($message, $type); fwrite($logger_file, $content); fclose($logger_file); } /* private method to build logfile message can be overridden to create different log format expects: STRING message returns: STRING log_entry */ function _buildMessage($message, $type) { $log_entry = date("d.m.Y :: H:m:s")." :: ". str_pad(substr($GLOBALS["REMOTE_ADDR"]." ", 0, 15), 20, ".", STR_PAD_RIGHT)." ". str_pad($GLOBALS["user_name"], 25, ".", STR_PAD_RIGHT). str_pad(substr($GLOBALS["PHP_SELF"], strrpos($GLOBALS["PHP_SELF"], "/"), strlen($GLOBALS["PHP_SELF"])), 30, ".", STR_PAD_RIGHT). "<$type> $message\n"; return $log_entry; } } ?>
|