13-05-2006, 12:59
|
|
|
חבר מתאריך: 13.04.06
הודעות: 48
|
|
צריך ביקרות ועצות למחלקה שבניתי לloging
שלום, בניתי מחלקה שאיתה אני אשתמש לעשות לוגים בזמן התיכנות.. עכשיו רציתי לדעת את דעתכם מה כדאי לשפר פה.
קוד PHP:
class Log { var $log_directory = "logs/"; var $log_maxfilesize = 100000; # DO NOT TUCH UNDER HERE! var $log_fileformat_change = ""; var $log_files = ""; var $log_fileformat = 'log.%NUM%.html'; var $log_levels = array(NONE => 0,ERROR => 1,INFO => 2,DEBUG => 3); function Log(){ $this->log_update_directory_content(); $this->log_fileformat_change = $this->log_fileformat; if( ( @filesize( $this->log_directory.$this->log_files[0] ) > $this->log_maxfilesize ) || ( $this->log_files[0] == ".." ) ){ if( $this->log_last_log_id() == false ){ $fileFormat = $this->log_files[0] = str_replace("%NUM%", "1", $this->log_fileformat_change); } else { $fileFormat = str_replace("%NUM%", $this->log_last_log_id() + 1, $this->log_fileformat_change); } @copy( $this->log_directory.$this->log_files[0] , $this->log_directory.$fileFormat ); fwrite( fopen( $this->log_directory.$fileFormat , "w+" ) , "" ); $this->log_add( info, "Log file created - ".$this->log_directory.$fileFormat ); } } function log_add( $level, $message ) { $var = str_replace( "%NUM%", $this->log_last_log_id(), $this->log_fileformat_change ); $fd = fopen( $this->log_directory.$var , "a+" ); fwrite( $fd, $this->log_html_format( $level , $message ) ); fclose($fd); } function log_html_format( $error, $message ){ return "=> <span style='width:60px'>".strtoupper($error).'</span> => ['.date("M d, Y H:G:s").'] => '.$message."<br>"; } function log_update_directory_content(){ if( !is_dir( $this->log_directory ) ) @mkdir( $this->log_directory, 0777 ); $this->log_files = @scandir( $this->log_directory , 1 ); } function log_last_log_id(){ $this->log_update_directory_content(); if( $this->log_files[0] == ".." ) return false; $last = explode( ".", $this->log_files[0] ); return $last[1]; } function log_delete() { $last = $this->log_last_log_id(); if( $last != false ){ for( $x=1; $x <= $last ; $x++ ){ $this->log_fileformat_change = $this->log_fileformat; $var = str_replace( "%NUM%", $x, $this->log_fileformat_change ); @unlink( $this->log_directory.$var ); } } } } $class = new Log(); $class->log_add( error, "error msg");
הקוד מוציא בתיקייה
logs/log.1.html
רישומים ובמקום המספר זה גודל כל הזמן אם הקובץ עבר את המגבלה נגיד כל 100 קילו בית של לוג נפתח אחד חדש.
בלוג נרשם משהו כזה
=> INFO => [May 13, 2006 13:13:12] => Log file created - logs/log.1.html
ואיך גם אפשר לקצר את זמן העיבוד למרות שהוא ממש קצר 0.001 משהו כזה
דעתכם חשובה לי
|