Changeset 247 for branches/comu


Ignore:
Timestamp:
2007/02/14 12:49:52 (17 years ago)
Author:
kakinaka
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/comu/data/lib/glib.php

    r15 r247  
    9696        fclose( $fp ); 
    9797        gfPrintLog("*** end Debug ***"); 
     98 
     99        // ¥í¥°¥Æ¡¼¥·¥ç¥ó 
     100        gfLogRotation(MAX_LOG_QUANTITY, MAX_LOG_SIZE, LOG_PATH); 
    98101} 
    99102 
     
    123126        fwrite( $fp, $today." [".$_SERVER['PHP_SELF']."] ".$mess." from ". $_SERVER['REMOTE_ADDR']. "\n" ); 
    124127        fclose( $fp ); 
     128    } 
     129     
     130    // ¥í¥°¥Æ¡¼¥·¥ç¥ó 
     131    gfLogRotation(MAX_LOG_QUANTITY, MAX_LOG_SIZE, $path); 
     132} 
     133 
     134/**          
     135 * ¥í¥°¥í¡¼¥Æ¡¼¥·¥ç¥óµ¡Ç½            
     136 *           
     137 * @param integer $max_log ºÇÂç¥Õ¥¡¥¤¥ë¿ô 
     138 * @param integer $max_size ºÇÂ祵¥¤¥º 
     139 * @param string  $path ¥Õ¥¡¥¤¥ë¥Ñ¥¹ 
     140 * @return void ¤Ê¤· 
     141 */          
     142function gfLogRotation($max_log, $max_size, $path) { 
     143     
     144    // ¥Ç¥£¥ì¥¯¥È¥ê̾¤ò¼èÆÀ 
     145    $dirname = dirname($path); 
     146    // ¥Õ¥¡¥¤¥ë̾¤ò¼èÆÀ 
     147    $basename = basename($path); 
     148     
     149    // ¥Õ¥¡¥¤¥ë¤¬ºÇÂ祵¥¤¥º¤òĶ¤¨¤Æ¤¤¤Ê¤¤¤«¥Á¥§¥Ã¥¯ 
     150    if(filesize($path) > $max_size) { 
     151        if ($dh = opendir($dirname)) { 
     152            while (($file = readdir($dh)) !== false) { 
     153                // ¥í¥°¥í¡¼¥Æ¡¼¥·¥ç¥ó¤Ë¤ÆºîÀ®¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤ò¼èÆÀ 
     154                if(ereg("^". $basename . "\." , $file)) { 
     155                    $arrLog[] = $file; 
     156                } 
     157            } 
     158             
     159            // ¥Õ¥¡¥¤¥ë¥í¥°¤¬ºÇÂç¸Ä¿ô¤Ê¤é°Ê¾å¤Ê¤é¸Å¤¤¥Õ¥¡¥¤¥ë¤«¤éºï½ü¤¹¤ë 
     160            $count = count($arrLog); 
     161            if($count >= $max_log) { 
     162                $diff = $count - $max_log; 
     163                for($i = 0; $diff >= $i ; $i++) { 
     164                    unlink($dirname. "/" .array_pop($arrLog)); 
     165                }    
     166            } 
     167             
     168            // ¥í¥°¥Õ¥¡¥¤¥ë¤Îź¤¨»ú¤ò¤º¤é¤¹ 
     169            $count = count($arrLog); 
     170            for($i = $count; 1 <= $i; $i--) { 
     171                $move_number = $i + 1; 
     172                 
     173                if(file_exists("$path.$move_number")) unlink("$path.$move_number"); 
     174                copy("$dirname/" . $arrLog[$i - 1], "$path.$move_number");       
     175                 
     176            } 
     177            $ret = copy($path, "$path.1"); 
     178             
     179            // ¿·µ¬¥í¥°¥Õ¥¡¥¤¥ë¤òºîÀ® 
     180            if($ret) { 
     181                unlink($path);           
     182                touch($path); 
     183            } 
     184        } 
    125185    } 
    126186} 
Note: See TracChangeset for help on using the changeset viewer.