/**
  * ログローテーション機能
  *
  * XXX この類のローテーションは通常 0 開始だが、本実装は 1 開始である。
  * この中でログ出力は行なわないこと。(無限ループの懸念あり)
  *
  * @param integer $max_log
  *            最大ファイル数
  * @param integer $max_size
  *            最大サイズ
  * @param string $path
  *            ファイルパス
  * @return void
  */
 function gfLogRotation($max_log, $max_size, $path)
 {
     // 終了条件
     if (!@is_file($path)) {
         return;
     }
     if (@filesize($path) <= $max_size) {
         return;
     }
     if (preg_match("{" . date("Y/m/d/a") . "}", $path)) {
         $arrFiles = glob("{$path}.*");
         $arrFilesCount = count($arrFiles);
         $max_log = $arrFilesCount + 2;
         // Archiveログの場合は無尽蔵
         GC_Utils::gfLogRotation($max_log, $max_size, $path);
     } else {
         // 通常ログの場合は設定値
         GC_Utils::gfLogRotation($max_log, $max_size, $path);
     }
 }
Example #2
0
 function gfPrintLog($mess, $path = '')
 {
     // 日付の取得
     $today = date("Y/m/d H:i:s");
     // 出力パスの作成
     if ($path == "") {
         $path = LOG_PATH;
     }
     // エスケープされている文字をもとに戻す
     $trans_tbl = get_html_translation_table(HTML_ENTITIES);
     $trans_tbl = array_flip($trans_tbl);
     $mess = strtr($mess, $trans_tbl);
     $fp = fopen($path, "a+");
     if ($fp) {
         fwrite($fp, $today . " [" . $_SERVER['PHP_SELF'] . "] " . $mess . " from " . $_SERVER['REMOTE_ADDR'] . "\n");
         fclose($fp);
     }
     // ログテーション
     GC_Utils::gfLogRotation(MAX_LOG_QUANTITY, MAX_LOG_SIZE, $path);
 }